From 73bf9812dd07f5aadae48988ef9948d2da93c3d6 Mon Sep 17 00:00:00 2001 From: MattMo Date: Tue, 13 Sep 2022 21:10:42 -0700 Subject: [PATCH] Added IgniteProperty create method to construct properties onto any object in the same way they are done for components. --- ignite-html.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ignite-html.js b/ignite-html.js index 4a190a5..d1de50b 100644 --- a/ignite-html.js +++ b/ignite-html.js @@ -48,6 +48,25 @@ class IgniteProperty { this.patchArray(); } + /** + * Creates a new ignite property on the target object that responds to rendering states. + * @param {Any} target + * @param {String} name + * @param {Any} value + * @returns {Any} The target passed to the function. + */ + static create(target, name, value) { + var property = new IgniteProperty(value); + + Object.defineProperty(target, name, { + get: () => { return (IgniteRendering.rendering ? property : property.value); }, + + set: (value) => { property.value = value; } + }); + + return target; + } + /** * Gets the value of this IgniteProperty. * @returns {Any} The value of this IgniteProperty.