Skip to content

Instantly share code, notes, and snippets.

@zackthehuman
Created August 20, 2016 02:51
Show Gist options
  • Save zackthehuman/a0a43a8ec6abeb0d8d08c6e9688f96fa to your computer and use it in GitHub Desktop.
Save zackthehuman/a0a43a8ec6abeb0d8d08c6e9688f96fa to your computer and use it in GitHub Desktop.
Contrived CP example
import Ember from 'ember';
function makeCP(keys, cb) {
keys = keys.map(key => `someObj.${key}`);
const args = [...keys, cb];
return Ember.computed(...args);
}
const someObj = {
thePeople: 'are real',
theCases: 'are real',
theRulings: 'are final'
};
const theKeys = Object.keys(someObj);
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
foo: makeCP(theKeys, function() {
return this.get('someObj.thePeople');
}),
someObj
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{foo}}
<input oninput={{action (mut someObj.thePeople) value="target.value"}}>
<br>
<br>
{
"version": "0.10.4",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment