Skip to content

Instantly share code, notes, and snippets.

@k-fish
Last active November 22, 2016 19:17
Show Gist options
  • Save k-fish/cffa6f9efd5214e248a5c2a8fb6b0512 to your computer and use it in GitHub Desktop.
Save k-fish/cffa6f9efd5214e248a5c2a8fb6b0512 to your computer and use it in GitHub Desktop.
Runloop Async Issues
import Ember from 'ember';
export default Ember.Component.extend({
green() {
this.$().css('background-color', 'green');
},
red() {
this.$().css('background-color', 'red');
},
didInsertElement() {
this._super(...arguments);
// Iffy runloop code
Ember.run.later(this, this.green, 2);
Ember.run.next(this, this.red);
// End runloop code
//this.attrs.hasInserted();
},
willDestroyElement() {
this.attrs.willDestroy();
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
show: true,
actions: {
hasInserted() {
Ember.run.later(this, function() {
this.set('show', false);
}, 100);
},
willDestroy() {
Ember.run.later(this, function() {
this.set('show', true);
}, 20);
}
}
});
{{#if show}}
{{runloop-example
hasInserted=(action 'hasInserted')
willDestroy=(action 'willDestroy')
}}
{{/if}}
{
"version": "0.10.6",
"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.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment