Skip to content

Instantly share code, notes, and snippets.

@vcipriani
Last active October 19, 2018 17:30
Show Gist options
  • Save vcipriani/0661c149329ee4c647ca832bd0cad036 to your computer and use it in GitHub Desktop.
Save vcipriani/0661c149329ee4c647ca832bd0cad036 to your computer and use it in GitHub Desktop.
Define Property
import Ember from 'ember';
import { defineProperty } from '@ember/object';
export default Ember.Controller.extend({
init() {
setTimeout(() => {
// This line works and is deprecated
this.set('delayedProperty', Ember.computed(() => 'foo'));
// Using defineProperty() does not trigger any computed properties that are watching the property (eg. textToShow)
// defineProperty(this, 'delayedProperty', Ember.computed(() => 'foo'));
// Just logging value for proof that delayedProperty does contain the correct value when set via defineProperty
console.log('Delayed Property Value is:', this.delayedProperty);
}, 2000);
},
delayedProperty: 'bar',
textToShow: Ember.computed('delayedProperty', function() {
return this.get('delayedProperty');
})
});
<h1>Should change from bar to foo after 2sec ->{{textToShow}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.15.0",
"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.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment