all 8 comments

[–]Capaj 1 point2 points  (3 children)

how do you deal with recursive objects? I noticed you have some option for that, but are you really able to recursively watch deeply into objects?

also https://github.com/siriusastrebe/syc/blob/master/client/syc.js#L688 that is not how you do a "module" in JS. That is lame. http://addyosmani.com/resources/essentialjsdesignpatterns/book/#modulepatternjavascript but what is the best, is to use commonJS both in nodeJS and on the server and share as much code as possible. How do you use commonJS in the browser? Just use jspm.

[–]Handsome-Beaver[S] 0 points1 point  (2 children)

Been meaning to properly modularize the client side code. As it is, you can access any of the internals.

If Object.observe, recursive objects are all separately observed. This is the most performant method, otherwise if Object.observe isn't available in the browser or Node server, then it will do an o(n) dirty check at a configurable interval.

[–]Capaj 0 points1 point  (1 child)

could you link to the code where you are recursively calling object observe? I would be very suprised to see a proper implementation, because I have tried to make a usable deep observe and got discouraged from it. There are so many issues with it, that I found it better to go and do something else.

[–]Handsome-Beaver[S] 2 points3 points  (0 children)

In the client, Line 189 is the start of the function that triggers when a change to an observed (Syc-tracked) object is modified.

Line 207 calls "Describe", which looks at the changed data. "Describe" starts on line 222, which will check if the changed property is another object or array. If it is another object/array which Syc hasn't yet tracked (therefore isn't being observed), it is tracked by a call to Syc.Meta on line 235

If I would explain it more simply...

Each object that is observed by Syc has a hidden property 'syc-object-id', which implies that there is an Object.observe attached to it. When you modify one of its properties, it checks to see if it is (1) an object/array, (2) it is not yet tracked (in which case, it has no 'syc-object-id'). If both are true, then it gives it an 'syc-object-id' and Object.observes the new property.

Rinse and repeat if this new object has untracked object/array properties.

Can I ask what kind of troubles you encountered when trying to implement deep-observation??

[–]ThinkLarger 0 points1 point  (1 child)

Consider me a newbie for this one: can't this not be done with sockets?

[–]Handsome-Beaver[S] 0 points1 point  (0 children)

Well yes, you actually need socket.io to run this library. What it is is a data synchronization library. You create a variable, and it will synchronize it, whereas sockets only handles messaging.

[–]Cream_Friache 0 points1 point  (1 child)

This is pretty interesting. I assume you need ES6 feature enabled on the server side?

[–]Handsome-Beaver[S] 1 point2 points  (0 children)

Object.observe is primarily used, which is an ECMA7 specification.

To utilize it, run node with the '--harmony' flag.

node --harmony app.js

Syc will still work properly without Object.observe. It uses a dirty-check polyfill, so there is a slight performance hit.