-
Notifications
You must be signed in to change notification settings - Fork 16
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
Initial port of the bind
helper from ember-microstates
#1
Conversation
Ported from the `bind` helper in [ember-microstates](https://github.com/cowboyd/ember-microstates/blob/master/addon/initializers/register-bind-helper.js)
I think just write an acceptance test against the dummy app. Make sure that you see the |
click the button programatically, and see if it indeed toggles!. |
|
||
get toggle() { | ||
return () => { | ||
set(this, 'value', !get(this, 'value')); |
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.
Ember automatically installs a setter, you can probably just
this.value = !this.value;
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 started out with that approach actually, and was surprised to find that it didn't work.
Ember.set
seems to be the key in getting the template itself to realize that the underlying value has changed. Ember even gives this nifty error message in that case:
Uncaught Error: Assertion Failed: You must use Ember.set() to set the
valueproperty (of [object Object]) to
true.
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 stand corrected 🙇
@cowboyd good call on the acceptance test idea. I've added a mocha acceptance test with 4 cases (including binding falsey values). |
Added
let
helper as an initializer in the addon, and set up a small dummy app. Not sure how to test it yet since it's a handlebars helper wrapped in an initializer.cc @cowboyd