Skip to content

Instantly share code, notes, and snippets.

@ramybenaroya
Created February 19, 2019 08:13
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 ramybenaroya/e7916267e2107eb1d903c68d5e92384d to your computer and use it in GitHub Desktop.
Save ramybenaroya/e7916267e2107eb1d903c68d5e92384d to your computer and use it in GitHub Desktop.
SO-54749173
import Ember from 'ember';
export default Ember.Controller.extend({
cp1: 0,
promiseValue: null,
cpPromise: Ember.computed('cp1', function(){
return new Ember.RSVP.Promise((resolve, reject) => {
resolve(Math.floor(Math.random() * 1000))
})
}),
init(){
this._super()
setInterval(Ember.run.bind(this, function() {
this.incrementProperty('cp1')
Ember.run.later(this, function() {
this.get('cpPromise').then(Ember.run.bind(this, function(value){
this.set('promiseValue', value)
}))
})
}), 1000)
}
});
<h1>Promise Value:</h1>
<h3>{{promiseValue}}</h3>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment