Skip to content

Overwrites and breaks Backbone.sync #2

@sderickson

Description

@sderickson

Other collections which use the standard Backbone syncing functionality end up running the custom Backbone.sync function, which stop the normal sync process. To fix this I had the SharedCollection add function put a 'shared' flag on each model that is added, and then in the Backbone.sync function if that flag is not present it passes things along to the normal Backbone.sync method.

...

oldSync = Backbone.sync

Backbone.sync = (method, model, options) ->

Call options.success() callback to trigger destroy event which triggers

synchronization to other browsers.

unless model.shared
return oldSync(method, model, options)

if method is "delete"
options.success(model, null, options)

...

add: (models, options) ->
if not models or models.length is 0
return this

if not _.isArray models
  models = [ models ]

model.shared = true for model in models

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions