alekseykulikov / backbone-offline

[Deprecated] Allows your Backbone.js app to work offline
MIT License
720 stars 56 forks source link

Saving a model doesn't sync with server. #19

Closed ekampp closed 11 years ago

ekampp commented 12 years ago

Hi there.

First problem:

I have a collection from where I grabbed a single model. I then set a variety of values on said model using the set method supplied by Backbone.

My immediate expectation is that this will automatically dirty the record. Is this in fact expected behaviour if not, how should I dirty a record?

Second problem:

I set the dirty attribute manually in order for the model to be present in the @collection.dirty() collection, and then I call @collection.storage.sync.incremental() (where @collection is the model's collection).

My immediate expectation here is that this would sync the now dirty collection with the backend, but that is not the case.

My code

Here is the code, from the edit view:

@model.set({ some: "attribute", has: "a value" })
@model.save { dirty: true },
  success: =>
    @collection.storage.sync.push()

Am I doing something wrong?

alekseykulikov commented 12 years ago

Hi @ekampp

If you changed the model with collection attribute, it should set dirty automatically. You can check example https://github.com/Ask11/dreamy and see that no magic and special additions.

ekampp commented 12 years ago

Ok. I found out, that it was partly my fault for leaving some residual code behind after another attempt at local storage, thank you. :+1:

But I'm still facing some problems. Primarily with @collection.destroyDiff(response) on line 235, which seams to fetch all the records in the collection again, so using the incremental sync doesn't push anything to the server.

If I comment out this line the incremental sync works fine. But that leaves each article in the local storage twice. If I move the line to after the push it removes all but the dirty article.

alekseykulikov commented 12 years ago

destroyDiff - remove oldest items, you can't comment it. incremental sync push only dirty items. I'm not sure that I understand your question, can you get an example?