Last active
September 20, 2018 08:32
-
-
Save manufitoussi/9dba32465b451f67368b0868e29e7f7f to your computer and use it in GitHub Desktop.
Test Values in prototype
This file contains hidden or 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'; | |
var MyObj = Ember.Object.extend({ | |
obj: Ember.computed({ | |
get() { | |
var Obj = class Obj { | |
shrinkValues() { | |
Object.keys(this).forEach(key => { | |
if(this[key] === Obj.prototype[key]) { | |
delete this[key]; | |
} | |
}); | |
} | |
}; | |
Obj.prototype.prop1 = 'default1'; | |
Obj.prototype.prop2 = 'default2'; | |
Obj.prototype.prop3 = 'default3'; | |
Obj.prototype.prop4 = 'default4'; | |
return new Obj() | |
} | |
}).readOnly() | |
}); | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
init() { | |
this._super(); | |
this.myObj = MyObj.create(); | |
this.myObj.obj.prop1 = 1; | |
Ember.set(this.myObj, 'obj.prop2', 2); | |
Ember.set(this, 'myObj.obj.prop3', 3); | |
console.log('this.myObj.obj.prop1', this.myObj.obj.prop1); | |
console.log('this.myObj.obj.prop2', this.myObj.obj.prop2); | |
console.log('this.myObj.obj.prop3', this.myObj.obj.prop3); | |
console.log('this.myObj.obj.prop4', this.myObj.obj.prop4); | |
console.log('this.myObj.obj', this.myObj.obj); | |
Ember.set(this.myObj, 'obj.prop2', 'default2'); | |
this.myObj.obj.shrinkValues(); | |
console.log('this.myObj.obj.prop1', this.myObj.obj.prop1); | |
console.log('this.myObj.obj.prop2', this.myObj.obj.prop2); | |
console.log('this.myObj.obj.prop3', this.myObj.obj.prop3); | |
console.log('this.myObj.obj.prop4', this.myObj.obj.prop4); | |
console.log('this.myObj.obj', this.myObj.obj); | |
} | |
}); |
This file contains hidden or 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.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": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment