Comments (10)
I think that amplify.store is a pretty decent alternative to the offline storage that is in here now. It is (should be) pretty cross browser.
There are some attempts at porting the localStorage plugin that was used in offline to amplify.store. Some pretty successful. I'll have a stab at making this work in Backbone.offline.
Source:
http://amplifyjs.com/api/store/
from backbone-offline.
It's perfect idea and It will great if you add patch for aplify.store.
But I think IE6-7 support should be optional. When user included aplify.store + json2 then we're using amlify.
https://github.com/appendto/amplify/blob/master/store/amplify.store.js
When user included IDBStore and browser has IndexedDB support then we use it:
https://github.com/jensarps/IDBWrapper/blob/master/IDBStore.js
So we can give user ability to configure which storage-adapter he wants to use.
In Offline.Storage I have methods setItem, removeItem and getItem. We can extended them for more complex behavior.
from backbone-offline.
This is not so simple,
IndexedDB & websql are async, this means that you can not do this with current implementation.
from backbone-offline.
The other day I created a little adapter for Backbone.localStorage.
https://github.com/abuisman/Backbone.amplifyStorage
Might come in useful for someone.
from backbone-offline.
@abuisman, thanks for share
from backbone-offline.
@ask11 My pleasure. I hope you find it useful.
from backbone-offline.
Hello, I just made a modified version of backbone.offline to use IndexedDB, it worked very well for me, I basically hadn't to change anything on my backbone code, just backbone.offline file and added the YDN-DB library.
Check it out: https://github.com/rogeriochaves/backbone-indexeddb-offline
It wasn't fully tested, any errors let me know :)
from backbone-offline.
Thanks for sharing! Nice work on keeping this going.
What I wonder though is what motivated you to basically fork backbone-offline rather than writing an adapter for it like I did (see above). I compared the code of your fork and the original and there are many similarities. You could have written a new class that inherits from the original and then just override what you need.
More generally:
When we look at these efforts we might even be able to distill a storage-independent solution and work 100% through adapters.
This way backbone-offline will not define what you have to use as storage, but just provide you with an interface for the backbone piece of the puzzle. Adapters (which should be more modular than mine maybe) should then provide the actual storage piece.
What do we/you think?
p.s. If I am not mistaking: in your first method localSync
you have if method == 'read'
and later you have a switch with when 'read'
, but this will never be true, as the if would've passed and the switch is in the else.
from backbone-offline.
The thing is the current backbone.offline implementation was not async, and IndexedDB is, so I had to change many things to work properly, it was easier to me to change the code. But the code I made uses YDN-DB, which unifies IndexedDB, WebDatabase and WebStorage, so, change the storage now is easy (although I didn't tested with others storages yet).
But it is definitely a good idea to separate the backbone.offline core from it's storages, since storages specifications may still change, and the modules should worry about working with the browser, while the backbone.offline should worry to work with the current version of backbone.
Still, although it's a heavy library (about 100kb with the 3 storages), I liked very much to work with YDN-DB, because it's well maintained and it is so easy to use.
About the p.s., I putted that if method == 'read'
because it was the only method I really had to work asynchronously, and I forgot to remove it from the switch. Changed it already, thank you!
from backbone-offline.
Yes I see what you mean.
I guess it depends on how @ask11 feels about updating backbone-offline to work more modularly and allowing for modularity in picking storage engines.
Then again, it also depends on how much effort we all need/want to put into this. I mean if solution xyz works for someone, why think about and work on more of them? Also, it might even have a place within the backbone project to allow modular storage engines.
@rogeriochaves what would be great is that if you'd have some comprehensive tests so that we are able to automatically check whether your solution still works when backbone updates.
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.