Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Implements invokeHelper #19171

Merged
merged 1 commit into from
Oct 1, 2020
Merged

[FEAT] Implements invokeHelper #19171

merged 1 commit into from
Oct 1, 2020

Conversation

pzuraq
Copy link
Contributor

@pzuraq pzuraq commented Sep 30, 2020

Reopening #19165, thanks for getting it started @NullVoxPopuli!

Implements invokeHelper as described in RFC 626. Everything is behind a feature flag, ready to flip!

Copy link
Contributor

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

Eeeeeeeee 🎉

return getValue(DEBUG ? ARGS_CACHES!.get(proxy)! : proxy.argsCache!)!;
}

class SimpleArgsProxy {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does something like this already exist for modifiers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a more complicated version which proxies each individual argument. Using that would require users to pass in each arg as a function, which would be a bit prohibitive and is not what was spec'd. So, this one is a simpler proxy that basically calls the users compute function and then returns the proper value whenever positional or named is accessed.

}

let instance = managers.get(factory);

if (instance === undefined) {
instance = factory(owner);
instance = factory(owner!);
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you know that owner exists here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may actually be undefined, in the case of helper managers, but for modifier/component managers it will always exist at this point (since you are not currently allowed to pass an undefined owner to getModifierManager or getComponentManager). The types here are a bit messy, but I think it should be fine.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Looking really good! I left a few inline comments/questions, but I think we are also missing some test cases:

  • Usage of invokeHelper with custom helper managers (will need to be guarded by both feature flags, but should still be tested)
  • Ensuring that associating destructors to the the helper context works properly (for both Ember.Helper/Ember.Helper.helper helpers and custom helpers)
  • Usage of non-class based helpers
  • Confirming the caching of the computeArgs, specifically how many times the third argument is expected to be invoked in various contexts
  • Confirming that a helper that accesses none of the args (positional or named), and nothing else is "constant"
  • Confirming that a helper that accesses only args that themselves are constant (e.g. the computeArgs function is something that uses no tags), is constant

@pzuraq pzuraq force-pushed the invoke-helper branch 4 times, most recently from 6f3eb2a to e4c0450 Compare October 1, 2020 00:24
assert.equal(count, 2, 'helper called a second time');
}

'@test helper that with constant args is costant'(assert) {
Copy link
Member

Choose a reason for hiding this comment

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

Typo: costant -> constant

}
}
);

Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to be:

Suggested change
if (
EMBER_GLIMMER_HELPER_MANAGER &&
EMBER_GLIMMER_INVOKE_HELPER
) {

Specifically, if we enable one before the other (which almost always does happen) these tests may fail. As far as I can tell both features are required for these tests...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably hard to see but it was nested in the other if, I can see how that's confusing though. Updated to check both 👍

Copy link
Member

Choose a reason for hiding this comment

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

Ah, gotcha. The indentation was hard to spot on mobile for sure.

@rwjblue rwjblue merged commit b0bc40f into master Oct 1, 2020
@rwjblue rwjblue deleted the invoke-helper branch October 1, 2020 12:18
@rwjblue
Copy link
Member

rwjblue commented Oct 1, 2020

🎂👌💫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants