mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 22:52:40 +00:00
Move calculation of error states outside of render
Our previous approach was technically bad practice to calculate side-effects inside of the render step. We can separate that out as part of this refactor. Also use native javascript map instead of lodash.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
require('./errorBar.less');
|
||||
const React = require('react');
|
||||
const _ = require('lodash');
|
||||
|
||||
import Dialog from '../../../components/dialog.jsx';
|
||||
|
||||
@@ -9,13 +8,15 @@ const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
||||
const ErrorBar = (props)=>{
|
||||
let hasOpenError = false, hasCloseError = false, hasMatchError = false;
|
||||
|
||||
props.errors.map( err => {
|
||||
if(err.id === 'OPEN') hasOpenError = true;
|
||||
if(err.id === 'CLOSE') hasCloseError = true;
|
||||
if(err.id === 'MISMATCH') hasMatchError = true;
|
||||
});
|
||||
|
||||
const renderErrors = ()=>(
|
||||
<ul>
|
||||
{_.map(props.errors, (err, idx)=>{
|
||||
if(err.id === 'OPEN') hasOpenError = true;
|
||||
if(err.id === 'CLOSE') hasCloseError = true;
|
||||
if(err.id === 'MISMATCH') hasMatchError = true;
|
||||
return (
|
||||
{props.errors.map((err, idx)=>{
|
||||
<li key={idx}>
|
||||
Line {err.line} : {err.text}, '{err.type}' tag
|
||||
</li>
|
||||
|
||||
Reference in New Issue
Block a user