386255 (2) [Avatar] Offline
#1
First off, thanks for all your hard work on this book. It's a very interesting topic and I'm enjoying exploring it.

I'm in chapter 7 and you are using Object.observe to react to changes in the model within each plugin. However, this API has been deprecated and its not in the latest version of node.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe

You may be able to implement similar functionality with the ES6 Proxy feature.
domguinard (69) [Avatar] Offline
#2
Hi,

First: thanks a lot for the compliment, we are glad you enjoy the book!
Then in terms of Object.observe() we knew it was potentially going to be removed (there is a note in the book about that) from future versions.

The current LTS (version 4.X, supported until 2018-04-01) will keep supporting observe() but as you rightfully flagged the 6.X does not support it, which means the next LTS will not support it.
The problem with changing this is that the code relies on observe() quite a bit so we might not be able to change this before the book goes to print. Nevertheless we are now looking into a solution (such as the Proxy you suggested) and will upgrade the code accordingly on Git and keep you posted!
386255 (2) [Avatar] Offline
#3
Cool good to know. It's a shame they didn't keep Object.observe around because its very convenient and simple to use.
Vlad Trifa (16) [Avatar] Offline
#4
Hello, thanks for the feedback - this is the thing when you use node.js, by the time you wrote your app you can rewrite it given how quickly it changed (and we had to change quite a few things like this while writing the book just because how quickly node evolved).
431450 (10) [Avatar] Offline
#5
I try to change 7.12 Listing code into this but it seem not working.
[...]
exports.start = function () {
var objectToObserve = new Proxy(model, objectChangeHandler)
connectHardware();
};

var objectChangeHandler = {
get: function (target, prop) {
return Reflect.get(target, prop);
},
set: function (target, prop, value) {
console.info('Change detected by plugin for %s...', pluginName);
switchOnOff(value);
return Reflect.set(target, prop, value);
}
};
[...]

I has removed all simulation code because I have raspberry pi. I hope that you can help me improve this code. Thanks
431450 (10) [Avatar] Offline
#6
I resolved this by using WatchJS.
https://github.com/melanke/Watch.JS

Very useful library, I hope this can help someone like me.
domguinard (69) [Avatar] Offline
#7
Thanks for your post, watch.js is indeed one option thanks for that, we are now looking into this issue actively as the new Node LTS is 6 and it does not support observe(). Stay tuned on Git for progress:
https://github.com/webofthings/webofthings.js/issues/3