Backbone Dropbox Datastore API adapter
Quite simply a Dropbox Datastore adapter for Backbone. It's a drop-in replacement for Backbone.Sync() to handle saving to a Dropbox Datastore.
There is an implementation of TodoMVC using backbone.dropboxDatastore as storage.
You need to have registered application with an OAuth redirect URI registered on the App Console before using the Dropbox Datastore API.
Include Datastore API SDKs and Backbone.dropboxDatastore after having included Backbone.js:
To start using the Datastore API, you'll need to create a Client object. This object lets you link to a Dropbox user's account, which is the first step to working with data on their behalf.
After authentication you should set client object to Backbone.DropboxDatastore.client property.
Be sure to replace APP_KEY with the real value for your app.
var client = key: APP_KEY;// Try to finish OAuth authorization.clientauthenticateinteractive: false;// Redirect to Dropbox to authenticate if client isn't authenticatedif !clientisAuthenticated clientauthenticate;// Set client for Backbone.DropboxDatastore to work with DropboxBackboneDropboxDatastoreclient = client;// Client is authenticated and set for Backbone.DropboxDatastore.// You can use CRUD methods of collection with DropboxDatastore
Create your collections like so:
windowSomeCollection = BackboneCollectionextenddropboxDatastore: 'SomeCollection' // Unique name within your app.// ... everything else is normal.;
By default collections are not listen to changes of datastore that can be made by other application. In this case we don't see changes made in other instance of same application. If you want to make collection sync you should pass collection to syncCollection method of DropboxDatastore object:
windowSomeCollection = BackboneCollectionextenddropboxDatastore: 'SomeCollection'thisdropboxDatastoresyncCollectionthis;// ... everything else is normal.;
If you open multiple tabs with same application and change something all other window's collections updated automatically. You can check it if you open few tabs of Demo.
Under the hood it uses Dropbox.Datastore.RecordsChanged.
By default collections store on default Datastore. If you want use specific datastore pass options object as second attribute to Backbone.DropboxDatastore with property datastoreId:
windowSomeCollection = BackboneCollectionextenddropboxDatastore: 'SomeCollection'datastoreId: 'MyCustomDatastore'// ... everything else is normal.;
When your app makes a change to a datastore, that change is queued up locally and sent to Dropbox asynchronously. This means that there's a period of time between when a change is made and when that change has been uploaded to Dropbox.
To get current status of datastore you can just call getStatus() on dropboxDatastore object that returns 'uploading' or 'synced':
var currentStatus = myCollectiondropboxDatastoregetStatus;if currentStatus === 'uploading'// There are data that are not saved to Dropboxelse if currentStatus === 'synced'// All data are saved to Dropbox
Also you can listen to change status event on dropboxDatastore:
myCollectiondropboxDatastoreon'change:status'// do something...;
To fully removing created dropboxDatastore you should call close method on dropboxDatastore.
requireconfigpaths:jquery: 'lib/jquery'underscore: 'lib/underscore'backbone: 'lib/backbone'dropbox: ''dropboxdatastore: 'lib/backbone.dropboxDatastore';
Create client, authorize it and set to Backbone.DropboxDatastore.client as in previous section.
Define your collection as a module:
define'someCollection' 'dropboxdatastore'var SomeCollection = BackboneCollectionextenddropboxDatastore: 'SomeCollection' // Unique name within your app.;return ;;
Require your collection:
require'someCollection'// ready to use someCollection;
If you're using browserify.
BackboneDropboxDatastore = require'backbone.dropboxdatastore';
You'll need node and to
npm install before being able to run the minification script.
Also to install dependencies for tests you need to
npm install -g bower and then
- Write code, with tests;
- Run tests with
- Create a pull request.
Licensed under MIT license
Copyright (c) 2013 Dmytro Yarmak
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.