Mapped expressions refactor#4207
Conversation
7361bd1 to
a232e82
Compare
codehag
left a comment
There was a problem hiding this comment.
looks pretty good. i have concerns about ensureParserText -- it is too easy to do something wrong with it.
| // if the expression has a syntax error, | ||
| // we should show the error and avoid a dangerous evaluation. | ||
| const error = await parser.hasSyntaxError(expression.input); | ||
| if (error) { |
There was a problem hiding this comment.
the only thing changing between these cases is the value output. I would suggest that we separate the getting of the value from the dispatch; this way it is clear that only the value changes between the three cases
// can be outside of the scope
async function getExpressionValue(error, input) {
if (error) {
return { input, result: error };
}
if (!isPaused(getState()) {
return await client.evaluate(wrapExpression(input));
}
return await dispatch(evaluateInputAtFrame(input));
}
// ...
const value = await getExpressionValue(error, expression.input);
return dispatch({
type: "EVALUATE_EXPRESSION",
input: expression.input,
value
});| location | ||
| ); | ||
|
|
||
| await dispatch(ensureParserHasSourceText(generatedLocation.sourceId)); |
There was a problem hiding this comment.
I see two issues here:
ensureParserText is potentially.. doing a lot of things, and it is being used a lot. if a loadSource is in flight (for example, someone forgets an await somewhere), we may be retriggering it here, with no way of cancelling the original and as a result -- doubling the work.
second issue: "ensure" doesn't tell us that it is going to load the source text and then set the parser, so unless everyone who uses this function checks the definition, they will not see that it is not checking for a source (ensure suggests that "lets check if it is there, if not throw an error", similar to assert).
I think this needs to be renamed / possibly removed and the core problem addressed instead (better state management) -- what do you think?
There was a problem hiding this comment.
Good points, and I'm curious how they should be addressed.
-
maybe a state of
loadingon the source with the promise? so thatensurecan return it. -
I was also confused at the beginning, but now it makes sense to me.
ensureis not likeassert. But you could also call itloadSourceTextIfMissing(similar scheme toperformUpdateIfNecessaryfrom https://github.com/facebook/react/blob/v15.6.1/src/renderers/shared/stack/reconciler/ReactReconciler.js#L184) -
What do you mean in "better state management"?
There was a problem hiding this comment.
By better state management i mean introducing sagas :P but jason will give me serious side-eye for that one
the new mapping touches a lot of the Redux architecture. I think we should try to group the logic in actions/expressions because we're mapping expressions at the end of the day
Summary of Changes
The big architectural change is that i'm using dispatch to do priviledge work... not necessarily update the store.