Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit state event on component when state changes #482

Open
mStirner opened this issue Jul 7, 2024 · 0 comments
Open

Emit state event on component when state changes #482

mStirner opened this issue Jul 7, 2024 · 0 comments

Comments

@mStirner
Copy link
Member

mStirner commented Jul 7, 2024

In the endpoint item construction (class.endpoint.js), add a .emit(...) inside the state update callback:

this.states = obj.states.map((item) => {
return new State(item, () => {
try {
// feedback
scope.logger.verbose(`Value in endpoint ("${obj._id}") state ("${item._id}") changed: ${item.alias}=${item.value}`);
// update item in database
//await scope.update(this._id, this);
updater();
} catch (err) {
scope.logger.warn(err, `Could not update item (${obj._id}) state ("${item._id}") in database: ${item.alias}=${item.value}`);
}
});
});

to

        // see 407 & 420
        this.states = obj.states.map((item) => {
            return new State(item, () => {
                try {

                    // feedback 
                    scope.logger.verbose(`Value in endpoint ("${obj._id}") state ("${item._id}") changed: ${item.alias}=${item.value}`);

                    // notify listener event changed
                    scope.emit("state", item);

                    // update item in database 
                    //await scope.update(this._id, this); 
                    updater();

                } catch (err) {

                    scope.logger.warn(err, `Could not update item (${obj._id}) state ("${item._id}") in database: ${item.alias}=${item.value}`);

                }
            });
        });
@mStirner mStirner added this to the v4.0.0 release milestone Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant