Giter VIP home page Giter VIP logo

Comments (6)

alekseykulikov avatar alekseykulikov commented on July 19, 2024

Backbone.offline generated new ids for every new object which was added to storage. localStorage is like local DB. When you offline you can not generate id on server and you using local-id for consistence. You still can use Collection#get and it will be always correct no matter was synced this model or not. And feature with duplicate id controlling in the phase of sync. I agree that we should delegate it to Backbone, but now it's still not so.

Why I don't use cid:
Cid generated backbone and it's different between user sessions. You don't know which Backbone objects you will be use in current session. Although your idea is interesting and I should thinking about it and this way make library more flexible and more Backbone oriented.

Your way is not typical use case. You want to use backbone.offline as a temporary cache. That's mean that you should use sid for relations between other collections. But when you don't have a sid what id do you want to save to relational model?

from backbone-offline.

gilbert avatar gilbert commented on July 19, 2024

Thanks for the explanation. Since the app will be available offline, backbone.offline does fit my use case since I don't want to rely on the server to create tags.

I think I just need a way to tell backbone.offline "Here is a model from the server". Something like an update() method, or an option for pull(). This method/option would assume that the given model/data is already saved on the server, so it would copy over the id to sid and check for duplicates based on that.

Yes, an option to pull() does sounds like a good idea. It would use the data you give it instead of getting it from the server. Thoughts?

from backbone-offline.

alekseykulikov avatar alekseykulikov commented on July 19, 2024

I think we should use option in init mode like localId: false. It will work good when you don't want to relate your collection with others.
Bad offline case:
In offline mode you created a model and was generated id: sdhfshdkfj-sdfds-sdfsd-sdf. You connected this model with other models and saved primary ids. When you will sync this model which id will you use? We shouldn't change primary id on sync, it involves bad consequences.

from backbone-offline.

gilbert avatar gilbert commented on July 19, 2024

Does your bad offline case work with backbone.offline now? The option I'm suggesting would only be used when you receive data from the server from somewhere besides pull(). In other words, it will already have a proper id; backbone.offline would treat it as if it did come from pull(), changing the id and sid as it normally would.

from backbone-offline.

gilbert avatar gilbert commented on July 19, 2024

After studying the source code, it turns out there's already a method for this: Offline.Sync#pullItem. This fits what I need.

I'm going to be studying backbone.offline more extensively, since my app needs to be fully useable offline. Just fyi

from backbone-offline.

alekseykulikov avatar alekseykulikov commented on July 19, 2024

Ok. Glad to hear that you decided your problem and look forward for new experience and probably pull requests.
Good luck!

from backbone-offline.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.