Added IgniteObject to support full end to end properties.
This commit is contained in:
@ -11,11 +11,11 @@ class IgniteProperty {
|
||||
this.onShiftCallbacks = [];
|
||||
this.onUnshiftCallbacks = [];
|
||||
this.onSpliceCallbacks = [];
|
||||
|
||||
this.arrayCallbacks = [];
|
||||
this.reflected = [];
|
||||
this._value = val;
|
||||
this.ignoreValueChange = false;
|
||||
this.name = null;
|
||||
|
||||
//If we were passed options, add any callbacks needed.
|
||||
if (options) {
|
||||
@ -43,7 +43,7 @@ class IgniteProperty {
|
||||
this.attachOnSplice(options.onSplice);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Attempt to patch the value if it's a list.
|
||||
this.patchArray();
|
||||
}
|
||||
@ -361,6 +361,65 @@ Array.prototype.getOldPropertyValues = function (property, oldValue) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* The outline of an IgniteObject which contains IgniteProperties.
|
||||
*/
|
||||
class IgniteObject {
|
||||
/**
|
||||
* Creates a new IgniteObject from an object and returns it.
|
||||
* @param {Any} obj The object to create an IgniteObject out of.
|
||||
* @returns {IgniteObject} The ignite object created.
|
||||
*/
|
||||
constructor(obj) {
|
||||
//Only do this if the object is not an ignite object already.
|
||||
if (!(obj instanceof IgniteObject)) {
|
||||
Object.keys(obj).forEach(name => {
|
||||
var prop = new IgniteProperty(obj[name]);
|
||||
Object.defineProperty(this, name, {
|
||||
get: () => { return (IgniteRenderingContext.rendering ? prop : prop.value); },
|
||||
set: (value) => { prop.value = value; }
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks this IgniteObject for any properties not converted and automatically
|
||||
* converts them.
|
||||
*/
|
||||
update() {
|
||||
Object.keys(this).forEach(name => {
|
||||
if (!(this[name] instanceof IgniteProperty)) {
|
||||
var prop = new IgniteProperty(this[name]);
|
||||
delete this[name];
|
||||
Object.defineProperty(this, name, {
|
||||
get: () => { return (IgniteRenderingContext.rendering ? prop : prop.value); },
|
||||
set: (value) => { prop.value = value; }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an IgniteObject or Array of IgniteObjects and returns it.
|
||||
* @param {Object|Array} obj The object to create an IgniteObject from.
|
||||
* @returns {IgniteObject} The created IgniteObject.
|
||||
*/
|
||||
static create(obj) {
|
||||
if (obj instanceof Array) {
|
||||
var converted = [];
|
||||
obj.forEach(item => converted.push(new IgniteObject(item)));
|
||||
return converted;
|
||||
} else if (!(obj instanceof IgniteObject)) {
|
||||
return new IgniteObject(obj);
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The outline of a ignite callback that can be invoked and disconnected
|
||||
* to help maintain and cleanup callbacks.
|
||||
@ -457,9 +516,11 @@ class IgniteRenderingContext {
|
||||
}
|
||||
|
||||
window.IgniteRenderingContext = IgniteRenderingContext;
|
||||
window.IgniteObject = IgniteObject;
|
||||
|
||||
export {
|
||||
IgniteProperty,
|
||||
IgniteObject,
|
||||
IgniteRenderingContext,
|
||||
IgniteCallback
|
||||
};
|
Reference in New Issue
Block a user