gritzko / swarm

JavaScript replicated model (M of MVC) library
http://swarmdb.net/
MIT License
2.68k stars 97 forks source link

Model sync #65

Open hongnk opened 8 years ago

hongnk commented 8 years ago

I'm still trying to understand how Swarm works for collaborated editing.

Supposed one site created a new object extending a predefined model, how that new object be replicated to another site? I did observe an object with same ID that is already defined on both sites would be piped through, but a new object with new ID didn't seem to do so.

Perhaps I don't understand the flow clearly for the above? A code example will be great.

hongnk commented 8 years ago

Now I understand that the server side only forward models to listeners with known IDs. Perhaps new IDs need some sort of reference to be able to find listeners it must replicate to. I found Syncable.Ref in the code but not sure how it could be used. I hope there could be a way to define channel ID, where all objects belong to a channel would be replicated, regardless of object ID.

gritzko commented 8 years ago

Swarm is not channel-based. It is object-based. The typical approach is to put your objects into a collection with a predefined id, then open that collection. That way, a collection works as a "channel".

On 30 October 2015 at 23:39, hongnk notifications@github.com wrote:

Now I understand that the server side only forward models to listeners with known IDs. Perhaps new IDs need some sort of reference to be able to find listeners it must replicate to. I found Syncable.Ref in the code but not sure how it could be used. I hope there could be a way to define channel ID, where all objects belong to a channel would be replicated, regardless of object ID.

— Reply to this email directly or view it on GitHub https://github.com/gritzko/swarm/issues/65#issuecomment-152667435.

Victor

hongnk commented 8 years ago

Yes I thiink that works. The trick is to create a collection of Syncable.Ref, then all objects referenced in that collection will be replicated.