Giter VIP home page Giter VIP logo

backbone-parse's Introduction

backbone-parse

backbone-parse overrides the Backbone.Sync method to automatically persist your backbone models on Parse using their REST API. Saving you from all the manual plumbing.

Installation

Step 1:

Download backbone-parse.js and include it in your application after backbone.js e.g.

<script src="backbone-min.js"></script>
<script src="backbone-parse-min.js"></script>

Step 2:

Open backbone-parse.js and replace following at the top with your Parse credentials:

var application_id = "CkWCHMSOgyqoNKoIc5hu09uvdZcJ9rpHJD4iwhxI";
var rest_api_key = "H5SIwarTRXqd07C0OIZPbcRTYTNLKsjFAJt5PrFY";
var api_version = "1";

How to use it:

Initialization:

Create a Backbone model and set the parse class name:

var Item = new Backbone.Model({
	_parse_class_name: "Item";
});

Similarly for Collections:

var ItemsCollection = new Backbone.Collection({
	_parse_class_name: "Item";
});

This class name will specify backbone-parse which class persists this model on the Parse server. It is case sensitive. If the class doesn't already exists, Parse will automatically create one.

If the class name is not specified, then the model will be persisted using the default Backbone Sync (i.e. you'll need to specify a url)

Querying

Parse.com provides an API to query your data.

backbone-parse provides an easier method for specifying query constraints*. All you need is to pass the constraints in fetch method of Backbone.Collection. e.g.

var ItemCollection = new Backbone.Collection({
	_parse_class_name: "Item"
});

var items = new ItemCollection();
items.fetch({
	query: {"in_stock":true}
});

This will fetch all the items which are in stock. For details about what constraints you can pass, read: https://parse.com/docs/rest#queries

Feedback welcome.

TODO:

  • tests(!)
  • extend Backbone.Model to tackle Parse User objects

License

Distributed under MIT license.


*inspired by: http://houseofbilz.com/archives/2011/11/07/making-backbone-js-work-with-parse-com/

backbone-parse's People

Contributors

neebz avatar

Watchers

 avatar  avatar

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.