Is there a way to ensure that an observer receives notification of a change, regardless of Ember's assessment of property changes?
While the ember observer pattern typically works well for me, I've encountered a specific issue where I'm uncertain whether it's a bug, a feature, or something else entirely that's causing the problem.
In this scenario, I would greatly appreciate a method like
myinstance.fireNotificationsNoMatterWhat("cache")
to address the issue, but I haven't been able to find such functionality in the code. Am I overlooking something?
Below is a sample code snippet illustrating the problem.
<!DOCTYPE html>
<html>
<head>
<title>emberjs notification test</title>
<script src="jquery-1.6.1.min.js"></script>
<script src="ember-0.9.5.min.js"></script>
<script>
Test = Ember.Application.create({});
Test.cacheObject = Ember.Object.create({
"cache": {},
"add": function(key, value) {
this.propertyWillChange("cache");
var cache = this.get("cache");
cache[key] = value;
this.set("cache", cache);
this.propertyDidChange("cache");
},
});
Test.watcher = Ember.Object.create({
"cacheBinding": "Test.cacheObject.cache",
"obs": function() {
console.log("cache has changed:");
console.log(this.get("cache"));
}.observes("cache"),
});
setTimeout(function() {
Test.cacheObject.add("hello", "world");
}, 500);
setTimeout(function() {
Test.cacheObject.add("and", "universe");
}, 1000);
</script>
</head>
<body>
<h1>emberjs notification test</h1>
<h2>Please open your console to view the console.log output.</h2>
</body>
</html>
EDIT: While there are temporary solutions to the issue, I have attempted my own "fix" and explored Roy's suggestion, but I believe my fundamental question will remain unanswered until the enhancement request receives attention from the busy ember team. I am willing to wait for this if it eventually provides the functionality I require, similar to what ArrayProxy offers.