wipeoutjs / wipeout

A pure MVVM javascript framework based on knockout
http://wipeoutjs.github.io/wipeout
0 stars 2 forks source link

busybody.tryObserve vs busybody.observe #87

Closed ShaneGH closed 9 years ago

ShaneGH commented 9 years ago

Put in local (vm) and global (settings) flags which switch between observe and tryObserve for bindings. Maybe need a recursive makeObservable function too Or maybe something like

wo.viewModel("xxx")
    .observeModel("prop1")
    .observeModel("prop2.prop3")
    .observeModel("prop4*.prop5") // * is an array

-- or --

wo.viewModel("xxx")
    .autoObserve(true);

// which begets
xxx.onTemplateChange(function (template) {
    this.disposeOfPreviousObservablePaths();
    enumerateArr(template.getAllViewModelAndHtmlSetters(), function (setter) {
        if (setter.isFromModel)
            wo.makeObservablePath(setter);
    });
});

view.disposeOfPreviousObservablePaths = function () {
    enumerate(paths, function () {
        disposeOf(path);
        if (!path.object.hasAnyMoreSubscriptions()) {
            busybody.unMakeObservable(path.object);
        }
    });
}

// this will need changes to busybody:
    // busybody.unMakeObservable()
    // busybody.hasObservers()

// caveat: this code will need to be fired when something changes on the model
// caveat: this code will need to be fired before bindings are made