mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-02 17:12:45 +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');
|
require('./errorBar.less');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const _ = require('lodash');
|
|
||||||
|
|
||||||
import Dialog from '../../../components/dialog.jsx';
|
import Dialog from '../../../components/dialog.jsx';
|
||||||
|
|
||||||
@@ -9,13 +8,15 @@ const DISMISS_BUTTON = <i className='fas fa-times dismiss' />;
|
|||||||
const ErrorBar = (props)=>{
|
const ErrorBar = (props)=>{
|
||||||
let hasOpenError = false, hasCloseError = false, hasMatchError = false;
|
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 = ()=>(
|
const renderErrors = ()=>(
|
||||||
<ul>
|
<ul>
|
||||||
{_.map(props.errors, (err, idx)=>{
|
{props.errors.map((err, idx)=>{
|
||||||
if(err.id === 'OPEN') hasOpenError = true;
|
|
||||||
if(err.id === 'CLOSE') hasCloseError = true;
|
|
||||||
if(err.id === 'MISMATCH') hasMatchError = true;
|
|
||||||
return (
|
|
||||||
<li key={idx}>
|
<li key={idx}>
|
||||||
Line {err.line} : {err.text}, '{err.type}' tag
|
Line {err.line} : {err.text}, '{err.type}' tag
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user