alpaca
Version:
Alpaca provides the easiest and fastest way to generate interactive forms for the web and mobile devices. It runs simply as HTML5 or more elaborately using Bootstrap, jQuery Mobile or jQuery UI. Alpaca uses Handlebars to process JSON schema and provide
74 lines (57 loc) • 1.78 kB
JavaScript
(function($)
{
var Alpaca = $.alpaca;
/**
* Collection of observables.
*/
Alpaca.Observables = Base.extend(
{
constructor: function(scope)
{
this.base();
this.scope = scope;
this.observables = {};
},
observable: function(id, initialValue)
{
if (!this.observables[id])
{
var observable = new Alpaca.Observable(this.scope, id);
if (initialValue)
{
observable.set(initialValue);
}
this.observables[id] = observable;
}
// hand back from map
return this.observables[id];
},
dependentObservable: function(id, func)
{
var _this = this;
if (!this.observables[id])
{
var observable = this.observable(id);
// wrap the model
var m = new Alpaca.Observables(this.scope);
m.observable = function(x, y)
{
//Ratchet.debug("Observable: " + observable.id + " depends on observable: " + x);
var o = _this.observable(x, y);
o.markDependentOnUs(observable);
return o;
};
// create the value function (where "this" = the model)
var valueFunction = function() {
return func.call(m);
};
observable.setValueFunction(valueFunction);
}
return this.observables[id];
},
observables: function()
{
return this.observables;
}
});
})(jQuery);