jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.1k stars 5.39k forks source link

Specifying cid before Model creation #4176

Closed ppisecky closed 6 years ago

ppisecky commented 6 years ago

Hi,

We are currently working on a project using backbone. We have run into the issue where we need to synchronize models in real time across multiple users. We are not using a backend - backbone is only used as a utility to create Models and Collections. The problem is that at the moment a Model gets created at one users machine with a particular cid which we use to identify it later (in collections etc). Unfortunately when the model's JSON representation is sent over the network to another user and it is instantiated as a Model instance on his machine a new cid is generated by backbone which causes the two users enviroments to be desyncronized. Is there a way to tell backbone to use a particular cid when creating a model? I know that I can manually change it after model creation but that breaks our app's flow in terms of event listeners not being able to identify the model properly.

Thanks in advance for any help.

mr47 commented 6 years ago

@ppisecky You can use, idAttribute or http://backbonejs.org/#Collection-modelId to define, your generated ID, that can be sent over network, and will always be the same.

paulfalgout commented 6 years ago

Please use StackOverflow, the gitter channel, or the mailing list for questions. Github issues are for maintaining the framework only.