Skip to content

Instantly share code, notes, and snippets.

@nathanhammond
Last active January 26, 2017 05:56
Show Gist options
  • Save nathanhammond/927e2fb56cbabb1b66693389321c2dbc to your computer and use it in GitHub Desktop.
Save nathanhammond/927e2fb56cbabb1b66693389321c2dbc to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
let i = 0;
export default Ember.Controller.extend({
foo: function(event) {
console.log(++i, this, event);
},
actions: {
thing: function(event) {
// 1. You've passed off the function without the invocation context.
Ember.run(this.foo);
// 2. this works.
Ember.run(() => { this.foo(event) });
// 3. this works, it is a two step create + invoke thing.
// Use this when you want to pass the function out of Ember.
var result = Ember.run.bind(this, this.foo);
result(event);
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
});
<button onclick={{action 'thing'}}>thing</button>
{
"version": "0.11.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment