Skip to content

Automatically update items in databse when component schema has changed #75

@mStirner

Description

@mStirner

To automatically update items stored in the database collections, e.g added or removed field(s), a mechanism is need to sync the changes. Possible solution, this.items is proxied array:

const items = new Proxy([], {
    get(target, prop, receiver) {
        return target[prop];
    },
    set(obj, prop, value) {

        if (!["length"].includes(prop)) {

            // apply missing item properties here
            // verfiy object item, if verfiy fails, return false
            console.log("Add item: %j", value);

            //let { error } = schema.validate(value);
            //return error ? false : true;
            // save update obj in database?

        }

        obj[prop] = value;
        return true;

    }
});


//console.log(items)

try {

    items.push({
        name: "Room #1",
        enabled: true
    }, {
        name: "Room #2",
        enabled: true
    });

} catch (err) {
    console.log("Could not push", err);
}
//console.log(items[0])

With this its possible when the components init, add/remove properties.
Need to test how this affects the performance. How could we prevent that the check runs when component.add is called & through the joi.validate process goes. (First idea: check for the timestamp, if timestamps.created - Date.now() in push is smaller then x does nothing, if greather, run) How to not run this validation on every startup?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions