Skip to content

Instantly share code, notes, and snippets.

@ryanto
Created April 21, 2013 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanto/5428622 to your computer and use it in GitHub Desktop.
Save ryanto/5428622 to your computer and use it in GitHub Desktop.
EmberJS attribute bindings as promises.

I send the controller an event that will result in some long processing/work. Once this work is complete, I want the controller to update a binding. Ideally, I do not want th controller to know anything about this work, I simply want it to ask for the result.

In this example thingApi is an injected object that knows how to create new strings for things (done async). newString() is a function that returns a promise that eventually resolves to a string.

What I have to do:

    this.get('thingApi').newString().then(function(string) {
      this.set('thing', string);
    });

What I would like to do (hide the promise from the controller).

    this.set('thing', this.get('thingApi').newString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment