Created
April 12, 2017 13:25
-
-
Save courajs/ef7a9a9b86de23d6abfad0de7d6b195f to your computer and use it in GitHub Desktop.
Trampolined Properties
This file contains 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'; | |
let t = 0; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
theKey: 'one', | |
one: 1, | |
two: 2, | |
message: Ember.computed.alias('messageTrampoline.message'), | |
init() { | |
this._super(...arguments); | |
Ember.defineProperty(this, 'messageTrampoline', Ember.computed('theKey', function() { | |
let key = this.get('theKey'); | |
return Ember.Object.extend({ | |
message: Ember.computed('parent.'+key, function() { | |
let thing = this.get('parent.'+key); | |
return `Hi, ${thing}`; | |
}) | |
}).create({parent: this}); | |
})); | |
}, | |
actions: { | |
bump(key) { | |
this.incrementProperty(key); | |
}, | |
toggle() { | |
t++; | |
if (t % 2 === 0) { | |
this.set('theKey', 'one'); | |
} else { | |
this.set('theKey', 'two'); | |
} | |
} | |
} | |
}); |
This file contains 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