melanke / Watch.JS

watch the changes of any object or attribute

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting an object literal attribute with RequireJS does not trigger the passed callback function

opened this issue · comments

I am loading an object literal via RequireJs and passing it to an object which is at init time an "undefined" object:

define(["./bubbleChartModel", "../components/watch"], function (bubbleModel, watchJS) { 
var bubbleChartView = {

    model: {}, // doesn't work with model:undefined, as well

    initialize: function(modelObj) {
        var watch = watchJS.watch;
        var appDIV = "#chart-1";

        watch(bubbleChartView.model, function() {
            bubbleChartView.render();
        }); // passed 2,3 as depth but it did not work as well

        bubbleChartView.model = bubbleModel; //Render does not get called here!!!
    }

};

I tried to pass in numbers as depth but it did not work also. Is there any solution to this?

you should do this:

watch(bubbleChartView, "model", function() {
            bubbleChartView.render();
});