Fluid Fork Test
tests my extensions to the fluid core. fluidproject.org
by Warspawn
HTML
<script src="https://github.com/bsparks/infusion/raw/master/src/webapp/framework/core/js/Fluid.js"></script>
<div id="test">
SWEET!
</div>
JavaScript
/*
* observable.js
* a basic evented component designed to operate on it's model
* depends: jquery, fluid core
*/
// make sure namespace is setup
var olc = olc || {};
(function(undefined) {
olc.observable = function(options) {
var that = fluid.initEventedComponent("olc.observable", options);
// hide the model to force read-only?
var model = {};
that.getValue = function(field) {
return model[field] ? fluid.copy(model[field].value) : undefined;
};
that.setValue = function(field, value) {
if (!model[field]) {
model[field] = {};
}
var oldValue = model[field].value;
// only if it IS changed
if (oldValue !== value) {
model[field].value = fluid.copy(value);
// update any synced objects
if (model[field].sync) {
$.each(model[field].sync, function(index, o) {
o.obj.setValue(o.field, value);
});
}
that.fireEvent("modelchanged", [field, oldValue, value]);
}
};
// syncronize with another observable
that.sync = function(other, field, bidirectional) {
if (!model[field]) {
model[field] = {};
}
if (!model[field].sync) {
model[field].sync = [];
}
model[field].sync.push({
obj: other.obj,
field: other.field
});
if (bidirectional) {
other.obj.sync({
obj: that,
field: field
}, other.field, false);
}
};
//init
if (that.options.model) {
for (var f in that.options.model) {
$.each(that.options.model[f].sync, function(index, s) {
that.sync(s, f, true);
...