client/components/ianstormtaylor/reactive/0.13.2/lib/adapter.js
/**
* Default subscription method.
* Subscribe to changes on the model.
*
* @param {Object} obj
* @param {String} prop
* @param {Function} fn
*/
exports.subscribe = function(obj, prop, fn) {
if (!obj.on) return;
obj.on('change ' + prop, fn);
};
/**
* Default unsubscription method.
* Unsubscribe from changes on the model.
*/
exports.unsubscribe = function(obj, prop, fn) {
if (!obj.off) return;
obj.off('change ' + prop, fn);
};
/**
* Default setter method.
* Set a property on the model.
*
* @param {Object} obj
* @param {String} prop
* @param {Mixed} val
*/
exports.set = function(obj, prop, val) {
if ('function' == typeof obj[prop]) {
obj[prop](val);
} else {
obj[prop] = val;
}
};
/**
* Default getter method.
* Get a property from the model.
*
* @param {Object} obj
* @param {String} prop
* @return {Mixed}
*/
exports.get = function(obj, prop) {
if ('function' == typeof obj[prop]) {
return obj[prop]();
} else {
return obj[prop];
}
};