Last active
May 9, 2016 19:17
-
-
Save djmitchella/2621c293ca96819f6a1b to your computer and use it in GitHub Desktop.
computed property testing
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'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle' | |
}); | |
var Item = Ember.Object.extend({ | |
value: 0, | |
hasValue: Ember.computed.gte("value", 1) | |
}); | |
var ItemList = Ember.Object.extend({ | |
items: [], | |
itemsWithValue: Ember.computed.filterBy("items", "hasValue", true), | |
anyHaveValue: Ember.computed.notEmpty("itemsWithValue"), | |
showState: function() { | |
// Comment out the next line, and things start to work properly | |
console.log("anyHaveValue: " + this.get("anyHaveValue")); | |
}.observes("anyHaveValue") | |
}); | |
var row = ItemList.create(); | |
row.get("items").pushObject(Item.create()); | |
console.log(row.get("anyHaveValue")); // false, none of them do | |
row.get("items")[0].set("value", 1); | |
console.log(row.get("anyHaveValue")); // true | |
row.get("items")[0].set("value", 2); | |
console.log(row.get("anyHaveValue")); // should still be true, but if we have the console.log() line in the observes() function, it now shows incorrectly as false | |
row.get("items")[0].set("value", 3); | |
console.log(row.get("anyHaveValue")); // should still be true, but remains broken |
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.4.10", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment