Loopback VirtualParameters - good or evil?
Zaid Abdulla
zaid at genieacs.com
Tue Jul 4 19:46:39 EDT 2017
On Mon, 2017-07-03 at 11:42 +0200, Alexander Münn wrote:
> It states that "Virtual parameter scripts don't have the variable
> args" and further "Virtual parameter scripts have the variables
> timestamps and values.".
> In contrast the sandbox doesn't provide either 'timestamps' or
> 'values' variable. Instead I see the args array containing always(?)
> four objects. After some experimenting my interpretation of each
> element is:
>
> args[0] - reference timestamp on read access; empty on set
> args[1] - value object for writes; empty on get
> args[2] - some timestamps ?
> args[3] - last read value from device parameters
You're right. This has recently been changed from using two variables
(timestamps, values) to using args similar to provisions. This is in
order to be able to provide to the script the attribute timestamps and
values (3rd and 4th args) from the last time the vparam was executed.
It's a breaking change (sorry!) but I thought it's too small and too
important to be put it off until the next major release.
> On top of that I'm using following (loopback) VirtualParameter
> definition:
>
> const next = args[1];
> const last = args[3];
>
> /* default value */
> if (!last.value) {
> last.value = ["", "xsd:string"];
> }
>
> return {writable: true, value: next.value ? next.value :
> last.value};
>
>
> I'd like to discuss this "feature". Does anybody already use this or
> something similar?
I use something similar to this. Though my implementation is not as
elegant as yours :)
--
Zaid Abdulla <zaid at genieacs.com>
More information about the Users
mailing list