Content providers

Content providers creates interface for data modeling and data access.

Observing provider

Observing provider uses Object.observe to watch for deep model changes and notifies listeners when change occours.

Usage example

var provider = new Meta.ObservingProvider({
    myValue: 0,
    items: []
});

var handler = provider.on("changed", function(data){
    console.log("Data has changed");
});

provider.myValue = 1
//Logs: Data has changed

var item = { x: 0 };

provider.items.push(item);
//Logs: Data has changed

item.x = item.x + 1;
//Logs: Data has changed

provider.items.pull();
//Logs: Data has changed

provider.off("changed", handler);

provider.myValue = 2;
//Logs nothing

Constructor

var provider = new Meta.ObservingProvider({
    "default": "properties"
});

ObservingProvider(data)

Provider constructor.

If data parameter is set then data are merged to provider model.

Event binding and unbinding

var provider = new Meta.ObservingProvider();

var handler = function(model){
    //...   
};

provider.on("changed", handler);
provider.off("changed", handler);

on(eventName, handler)

Binds event handler.

off(eventName, handler)

Unbinds event handler.

Listening for changes

var provider = new Meta.ObservingProvider();

provider.on("changed", function(model){
    //...
});

changed

Provider fires changed event when model has changed.