-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Implement Ember.Helper: RFC#53. #11278
Conversation
Can you add a test that uses a service so we know the container is hooked up correctly? |
Tests are green (pending sauce), and I've addressed two items of @mmun feedback:
|
Yay :) |
@@ -1003,7 +1003,7 @@ Application.reopenClass({ | |||
registry.optionsForType('component', { singleton: false }); | |||
registry.optionsForType('view', { singleton: false }); | |||
registry.optionsForType('template', { instantiate: false }); | |||
registry.optionsForType('helper', { instantiate: false }); | |||
registry.optionsForType('helper', { singleton: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the singleton part isn't that important. The rest of the system should likely prefer lookupFactory(helperName).create(..)
anyways ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, per the TODO list I'm going to move to using lookupFactory
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Sorry I'm late to the party here. I see this example in the RFC // app/helpers/can-access.js
import Ember from "ember";
// Usage {{if (can-access 'admin') 'Welcome, boss' 'Heck no!'}}
export default Ember.Helper.extend({
session: Ember.inject.service(),
onCurrentUserChange: Ember.observes('session.currentUser', function() {
this.recompute();
}),
compute(params) {
const currentUser = this.get('session.currentUser');
return currentUser.can(params[0]);
}
}); I know that under the hood somehow this will use observers but should it be more abstracted so I can avoid owing @stefanpenner 10 bucks each time I write a Maybe an array property that under the hood will setup an observer and call // app/helpers/can-access.js
import Ember from "ember";
// Usage {{if (can-access 'admin') 'Welcome, boss' 'Heck no!'}}
export default Ember.Helper.extend({
session: Ember.inject.service(),
dependentKeys: ['session.currentUser'], // When this path changes recompute() is called
compute(params) {
const currentUser = this.get('session.currentUser');
return currentUser.can(params[0]);
}
}); |
@raytiley an earlier version of the RFC proposed that same API under the property
|
@@ -34,13 +34,13 @@ QUnit.module("ember-htmlbars: compat - Ember.Handlebars.get", { | |||
QUnit.test('it can lookup a path from the current context', function() { | |||
expect(1); | |||
|
|||
registry.register('helper:handlebars-get', function(path, options) { | |||
registry.register('helper:handlebars-get', new HandlebarsCompatibleHelper(function(path, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this manual wrapping should not be needed. If it is required does that mean we have broken exporting Handlebars style helpers from app/helpers/foo-bar.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussing with @mixonic, this is needed because we are wrapping eagerly when a helper is resolved (in the resolver changes in this PR). In this case, we are bypassing the resolver so this wrapping is required.
quick update: Is there any chance of this making it into 1.13? |
@cibernox si, it will go into 1.13. Just discussed it again at the f2f. I have one or two small changes but no more blockers, will land it by Sunday eve. |
@cibernox - Yes, it is absolutely critical that we land this into 1.13. |
I have punted on the ideal life-cycle for class-based helpers. The ideal is that an instance of a class-based helper lasts as long as its value is rendered on the page (even as that value changes), but is destroyed when the value is removed from rendering. Here, the instance is created and destroyed for every computation. This will likely change, but may not change until after 1.13 ships. This fact should not stop anyone from using these APIs. |
Will require tildeio/htmlbars#364 and a release for HTMLBars |
// Ember.Helper.build(function(params, hash) {}); | ||
Helper.reopenClass({ | ||
isHelperFactory: true, | ||
build(helperFn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you:
- rename this from
build
tohelper
- move it out of
reopenClass
(because we don't extended class to have ahelper
on their factories) - export a named
helper
function (for future ease in importing)
Should I update the blueprint in ember-cli? I assume that the shorthand function only helper is the preferred approach (for simplicity), but maybe adding a comment with an example how a full-fledged helper is a good idea. |
@cibernox I think a PR for that would be fantastic. I'm not sure what the right timing is to merge it into Ember-CLI, but the sooner we can get people off the old APIs the better. |
Implement Ember.Helper: RFC#53.
Implements emberjs/rfcs#53, new helpers.
For example:
TODO:
A bare function was resolved as a helper: This is not supported. Please upgrade your resolver, or use "Ember.Helper.build"
Create anember-helper
package?Ember.Helper
globallookupFactory
instead oflookup
for helpersrecompute
onb
in(a (b (c)))
b
in(a (b (c)))
A followup PR should deprecate these legacy APIs in 1.13.1:
Ember.Handlebars.makeBoundHelper
Ember.HTMLBars.makeBoundHelper
(private)HandlebarsCompatibleHelper
)