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

Initial port of the bind helper from ember-microstates #1

Merged
merged 9 commits into from
Jul 14, 2016
Merged

Conversation

cafreeman
Copy link
Contributor

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

@cowboyd
Copy link
Member

cowboyd commented Jul 14, 2016

I think just write an acceptance test against the dummy app. Make sure that you see the true text in your <li> where you expect, etc...

@cowboyd
Copy link
Member

cowboyd commented Jul 14, 2016

click the button programatically, and see if it indeed toggles!.


get toggle() {
return () => {
set(this, 'value', !get(this, 'value'));
Copy link
Member

@cowboyd cowboyd Jul 14, 2016

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;

Copy link
Contributor Author

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]) totrue.

Copy link
Member

Choose a reason for hiding this comment

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

I stand corrected 🙇

@cafreeman
Copy link
Contributor Author

@cowboyd good call on the acceptance test idea. I've added a mocha acceptance test with 4 cases (including binding falsey values).

@cowboyd cowboyd merged commit 17c296b into master Jul 14, 2016
@cowboyd cowboyd deleted the dev branch July 14, 2016 18:52
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.

2 participants