Skip to content

Instantly share code, notes, and snippets.

@jeffrey-biles-q2
Last active May 2, 2017 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffrey-biles-q2/9f1fd87bc66ab33f0fcd9ddd245b138d to your computer and use it in GitHub Desktop.
Save jeffrey-biles-q2/9f1fd87bc66ab33f0fcd9ddd245b138d to your computer and use it in GitHub Desktop.
proxying solution
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
user: Ember.inject.service(),
onControllerBool: true,
computedFromPolicy: Ember.computed.alias('user.policy.canFind')
});
import Ember from 'ember';
export default Ember.Controller.extend({
userThing: true,
computedThing: Ember.computed('userThing', function(){
return this.get('userThing');
}),
});
import Em from 'ember';
export default Em.Mixin.create({
unknownProperty: function(key) {
return this.get('proxy').get(key);
},
init() {
this._super(...arguments);
var controller = this.get('proxy');
for (var method in controller) {
if (typeof controller[method] === 'function') {
if (!this[method]) {
this.proxyMethod(method);
}
}
}
},
proxyMethod: function(method) {
this[method] = function() {
var controller = this.get('proxy');
return controller[method](...arguments);
};
},
});
import Ember from 'ember';
import ProxyMixin from '../mixins/proxy';
export default Ember.Controller.extend(ProxyMixin, {
proxy: Ember.computed(function() {
return this.container.lookup('controller:user');
})
});
<h1>Welcome to {{appName}}</h1>
<p>Both properties should change when clicking the checkbox</p>
user controller bool: {{input type="checkbox" checked=user.userThing}}
<br>
value of controller bool: {{user.userThing}}
<br>
value of computed off of controller bool: {{user.computedThing}}
<br>
<br>
{{outlet}}
<br>
<br>
{
"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": "1.13.13",
"ember-template-compiler": "1.13.13",
"ember-testing": "1.13.13"
},
"addons": {
"ember-data": "1.13.15"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment