Last active
July 20, 2017 10:26
-
-
Save buschtoens/2d505ae4881ff5703611586fc5e57543 to your computer and use it in GitHub Desktop.
Computed Property at runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { | |
computed: { collect, reads }, | |
defineProperty, | |
mixin, | |
propertyDidChange, | |
propertyWillChange, | |
run: { later }, | |
set | |
} = Ember; | |
function forceSet(obj, keyName, value) { | |
propertyWillChange(obj, keyName); | |
defineProperty(obj, keyName, value); | |
propertyDidChange(obj, keyName); | |
return value; | |
} | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
country: 'America', | |
description: 'land of the free', | |
init() { | |
later(() => { | |
// set(this, 'appName', collect('country', 'description')); | |
// defineProperty(this, 'appName', collect('country', 'description')); | |
// mixin(this, { appName: collect('country', 'description') }); | |
// this.appName = collect('country', 'description'); // Assertion Failed: You must use Ember.set() to set the... | |
forceSet(this, 'appName', collect('country', 'description')); | |
}, 2000); | |
later(() => { | |
set(this, 'description', 'land of the cinnabon'); | |
}, 4000); | |
later(() => { | |
// set(this, 'appName', reads('country')); // crashes | |
// defineProperty(this, 'appName', reads('country')); | |
// mixin(this, { appName: reads('country') }); | |
// this.appName = reads('country'); // Assertion Failed: You must use Ember.set() to set the... | |
forceSet(this, 'appName', reads('country')); | |
}, 6000); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment