Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Mapped expressions refactor#4207

Closed
jasonLaster wants to merge 3 commits into
firefox-devtools:masterfrom
jasonLaster:mapped-expressions-refactor
Closed

Mapped expressions refactor#4207
jasonLaster wants to merge 3 commits into
firefox-devtools:masterfrom
jasonLaster:mapped-expressions-refactor

Conversation

@jasonLaster

Copy link
Copy Markdown
Contributor

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.

@jasonLaster
jasonLaster force-pushed the mapped-expressions-refactor branch from 7361bd1 to a232e82 Compare September 29, 2017 02:55

@codehag codehag left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points, and I'm curious how they should be addressed.

  1. maybe a state of loading on the source with the promise? so that ensure can return it.

  2. I was also confused at the beginning, but now it makes sense to me. ensure is not like assert. But you could also call it loadSourceTextIfMissing (similar scheme to performUpdateIfNecessary from https://github.com/facebook/react/blob/v15.6.1/src/renderers/shared/stack/reconciler/ReactReconciler.js#L184)

  3. What do you mean in "better state management"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By better state management i mean introducing sagas :P but jason will give me serious side-eye for that one

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants