Comments (6)
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.
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.
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.
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.
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.
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)
- Fetch a simple Model ? HOT 4
- Fetch Local dont work with Backbone 1.0 HOT 4
- Bug with Storage#clear
- Collection is empty on fetching. Errors on POST request. HOT 5
- "Record Not Found" when fetching a model HOT 2
- Backbone.js offline not saving to local storage after fetch HOT 1
- error on fetch/pull HOT 3
- Backbone 1.0 and Backbone 0.9.10 compatibility difference
- Server implementation HOT 3
- Creates duplicate records if id is string HOT 1
- Option to use mongo objectid generator
- sync.push error
- collection.storage.sync.push() issue
- id not sent with this.model.save() HOT 1
- want to track the count of un-synced HTTP CRUD events
- Duplicate Add Event HOT 2
- delete que is never empty HOT 1
- Need help with updating related keys in multiple collections
- .storage.sync.full() alle Model data gets dirty HOT 1
- Using backbone-offline in conjuction with backbone.iobind?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone-offline.