![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
backbone.dropboxdatastore
Advanced tools
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:
<script type="text/javascript" src="backbone.js"></script>
<script type="text/javascript" src="backbone.dropboxDatastore.js"></script>
<script type="text/javascript" src="https://www.dropbox.com/static/api/dropbox-datastores-1.0-latest.js"></script>
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.
You'll want to create the client object as soon as your app has loaded. Depending on your JavaScript framework, this can be done in a variety of different ways. For example, in jQuery, you would use the $() function.
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 = new Dropbox.Client({key: APP_KEY});
// Try to finish OAuth authorization.
client.authenticate({interactive: false});
// Redirect to Dropbox to authenticate if client isn't authenticated
if (!client.isAuthenticated()) client.authenticate();
// Set client for Backbone.DropboxDatastore to work with Dropbox
Backbone.DropboxDatastore.client = client;
// Client is authenticated and set for Backbone.DropboxDatastore.
// You can use CRUD methods of collection with DropboxDatastore
Create your collections like so:
window.SomeCollection = Backbone.Collection.extend({
dropboxDatastore: new Backbone.DropboxDatastore('SomeCollection'), // Unique name within your app.
// ... everything else is normal.
});
For more details how Dropbox Datastore API works read tutorial: Using the Datastore API in JavaScript
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:
window.SomeCollection = Backbone.Collection.extend({
dropboxDatastore: new Backbone.DropboxDatastore('SomeCollection'),
initialize: function() {
this.dropboxDatastore.syncCollection(this);
},
// ... 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:
window.SomeCollection = Backbone.Collection.extend({
dropboxDatastore: new Backbone.DropboxDatastore('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 = myCollection.dropboxDatastore.getStatus();
if (currentStatus === 'uploading') {
// There are data that are not saved to Dropbox
} else if (currentStatus === 'synced') {
// All data are saved to Dropbox
}
Also you can listen to change status event on dropboxDatastore:
myCollection.dropboxDatastore.on('change:status', function(status, dropboxDatastore){
// do something...
});
Read more: Checking the datastore sync status in JavaScript.
To fully removing created dropboxDatastore you should call close method on dropboxDatastore.
myCollection.dropboxDatastore.close();
Include RequireJS:
<script type="text/javascript" src="lib/require.js"></script>
RequireJS config:
require.config({
paths: {
jquery: 'lib/jquery',
underscore: 'lib/underscore',
backbone: 'lib/backbone',
dropbox: 'https://www.dropbox.com/static/api/dropbox-datastores-1.0-latest',
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'], function() {
var SomeCollection = Backbone.Collection.extend({
dropboxDatastore: new Backbone.DropboxDatastore('SomeCollection') // Unique name within your app.
});
return new SomeCollection();
});
Require your collection:
require(['someCollection'], function(someCollection) {
// ready to use someCollection
});
If you're using browserify.
Backbone.DropboxDatastore = 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 bower install
.
npm test
Have fun!
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.
0.5.0 - Jan 1, 2014
FAQs
Backbone Dropbox Datastore API adapter
The npm package backbone.dropboxdatastore receives a total of 4 weekly downloads. As such, backbone.dropboxdatastore popularity was classified as not popular.
We found that backbone.dropboxdatastore demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.