Skip to content

Instantly share code, notes, and snippets.

@pzuraq
Last active August 1, 2018 20:58
Show Gist options
  • Save pzuraq/9bfa2297fefbe0a6686f487945595a08 to your computer and use it in GitHub Desktop.
Save pzuraq/9bfa2297fefbe0a6686f487945595a08 to your computer and use it in GitHub Desktop.
New Twiddle
import Component from '@ember/component';
import { or, readOnly } from '@ember/object/computed';
import { observer } from '@ember/object';
export default Component.extend({
unwrappedApi: or('api.api', 'api'),
foo: readOnly('unwrappedApi.foo'),
bar: readOnly('foo.bar'),
fooObserver: observer('bar', function() {
console.log('bar changed');
})
});
import Controller from '@ember/controller';
import { computed } from '@ember/object';
export default Controller.extend({
api: computed(() => {
return {
api: {
foo: {
bar: 123,
},
},
};
}),
actions: {
updateApi() {
this.set('api', {
api: {
foo: {
bar: 456,
},
},
});
},
},
});
{{outlet}}
{{test-component api=api}}
<button {{action 'updateApi'}}>
Update API
</button>
{
"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": "release",
"ember-template-compiler": "release",
"ember-testing": "release"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment