Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@lwmqn/smartobject-watchify
Advanced tools
An extension to make a Smart Object instance listenable to its resource changes
An extension to make a smartobject instance listenable to its resource changes
This module is used make a smartobject instance able to listen to its resource changes, which could be helpful for creating a machine node responsive to any reosurce change within it.
$ npm install smartobject-watchify --save
const SmartObject = require('@lwmqn/smartobject')
const soWatchify = require('@lwmqn/smartobject-watchify')
var so = new SmartObject()
so = soWatchify(so)
so.init('temperature', 0, { sensorValue: 31, units : 'C' })
// attach a listener to receive the change from resource 'temperature/0/sensorValue'
so.onChange('temperature/0/sensorValue', function (cVal, pVal) {
console.log('A listener to this resource')
console.log(cVal) // current value
console.log(pVal) // previous value
})
so.onChange('temperature/0/sensorValue', function (cVal, pVal) {
console.log('Another listener to this resource')
})
// Modify the sensorValue of the temperature sensor and the listener will be triggered
so.write('temperature', 0, 'sensorValue', 80, function (err, data) {
if (err) console.log(err)
})
smartobject-watchify
exports a function that receives the smartobject instance as the parameter to be extended and returned.
Arguments:
so
(Object): The instance of SmartObject class.Returns:
Examples:
const SmartObject = require('@lwmqn/smartobject')
const soWatchify = require('@lwmqn/smartobject-watchify')
const so = soWatchify(new SmartObject())
Attach a listener to observe a given resource for its change.
Arguments:
path
(String): The path to the resource, e.g. 'humidity/6/sensorValue'
.listener
(Function): function(cVal, pVal) {}
, where cVal
is the current value and pVal
is the previous value before updated.Returns:
Examples:
so.onChange('temperature/3/sensorValue', function (cVal, pVal) {
// Listen to 'temperature/3/sensorValue' for its change
})
Attach an one-time listener to observe a given resource for its change.
Arguments:
path
(String): The path to the resource, e.g. 'humidity/6/sensorValue'
.listener
(Function): function(cVal, pVal) {}
, where cVal
is the current value and pVal
is the previous value before updated.Returns:
Examples:
so.onChangeOnce('presence/7/dInState', function (cVal, pVal) {
// Listen to 'presence/7/dInState' only once for its change
})
Remove a specified listener from listening to the given resource path.
Arguments:
path
(String): The path to the resource, e.g. 'humidity/6/sensorValue'
.listener
(Function): The listener function.Returns:
Examples:
var presenceListener = function (cVal, pVal) {
// Listen to 'presence/7/dInState' only once for its change
}
// attach listener
so.onChange('presence/7/dInState', presenceListener)
// remove listener
so.removeListener('presence/7/dInState', presenceListener)
Remove all listeners from listening to the given resource path.
Arguments:
path
(String): The path to the resource, e.g. 'humidity/6/sensorValue'
.Returns:
Examples:
so.removeAllListeners('temperature/0/sensorValue')
Licensed under MIT.
FAQs
An extension to make a Smart Object instance listenable to its resource changes
We found that @lwmqn/smartobject-watchify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.