Skip to content

Instantly share code, notes, and snippets.

@MiguelMadero
Last active August 10, 2016 23:13
Show Gist options
  • Save MiguelMadero/210e38919af4fa51f25519f9b3c9ca84 to your computer and use it in GitHub Desktop.
Save MiguelMadero/210e38919af4fa51f25519f9b3c9ca84 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
let counter = 0;
const actualData = {x:1};
const queue = [];
const ProxyObject = Ember.ObjectProxy.extend({
unknownProperty (key) {
console.log('unkknownProperty was called', counter, key);
if (++counter < 15 ) {
//Ember.run.throttle(this,
// 'propertyDidChange', key, 0);
if (!queue.length) {
console.log('enqueueing')
// if the queue isn't empty we need to enqueue
// a change notification request, otherwise
// we already did
Ember.run.next(()=>this._notify());
}
queue.push(key);
}
return actualData[key] + counter;
},
_notify() {
console.log(queue);
queue.uniq().forEach(k=>this.propertyDidChange(k));
//queue.reset();
}
});
const proxyObject = ProxyObject.create();
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
proxy: proxyObject,
anotherProp: Ember.computed('proxy.x', function () {
console.log('anotherProp was called');
this.get('proxy.y');
return this.get('proxy.x');
}),
observeX: Ember.observer('proxy.x', function (key) {
console.log('observed x');
}),
observeY: Ember.observer('proxy.y', function (key) {
console.log('observed y');
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{proxy.x}}
{{anotherProp}}
{{outlet}}
<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": "1.13.13",
"ember-data": "2.7.0",
"ember-template-compiler": "1.13.13"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment