Coder Social home page Coder Social logo

deboned / backbone.syncer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from freak2geek/backbone-repository

0.0 2.0 0.0 154 KB

An extension of Backbone to track models, manage sync methods and help building online, offline and hybrid solutions. Supports LocalStorage via Locally plugin.

License: MIT License

JavaScript 100.00%

backbone.syncer's Introduction

Backbone.Syncer

The module is under development. It will be available soon.

Backbone helper that alters and add manager methods to Backbone Model and Collection. Provides a local cache to track models and supports LocalStorage. For managing the LocalStorage, Locally plugin is included in the library.

Table of Contents

Usage

Backbone.Syncer

storagePrefix

{String} Prefix that will be used for all data to store.

compressStorage

{Boolean} [default:false] Whether or not use compression in the storage.

storage()

Returns the Locally Store. Take a look to its API.

Backbone.Model

Class properties and methods

Model.create(attrs, [options])
  • attrs {Object} Attributes for the new instance.
  • options {Object} Options for the new instance.

Factory method that returns a model instance and ensures only one is gonna be created with same id. It keeps the instantiated models in a local cache collection.

Model.find(attrs)
  • attrs {Object} An id or cid for looking up.

Returns a model, by its id or cid, from the local cache collection of the model.

Model.all()

Returns the collection that represents the local cache of the model.

Model.reset()

Resets the local cache collection of the model.

Instance properties and methods

model.fetch([options])
  • options {Object} Options for the fetch call.
    • options.mode {String} [default:server]
      • infinite.

        Fetches the model locally if exists. Otherwise, remotelly.

      • server.

        Fetches the model remotely.

    • options.localStorage {Boolean} Whether or not use LocalStorage.
model.save(attrs, [options])
  • options {Object} Options for the save call.
    • options.mode {String} [default:server]
      • client.

        Updates the model locally. The changes no synchronized are kept for future pushes.

      • server.

        Updates the model both locally and remotely.

    • options.localStorage {Boolean|Object} Whether or not use LocalStorage or Locally options.
model.destroy([options])
  • options {Object} Options for the destroy call.
    • options.mode {String} [default:server]
      • client.

        Deletes the model locally. The destroy change no synchronized is kept for future pushes.

      • server.

        Deletes the model both locally and remotely.

    • options.localStorage {Boolean|Object} Whether or not use LocalStorage.
model.pull([options])
  • options {Object} Options for the fetch call.
    • options.localStorage {Boolean} Whether or not use LocalStorage.

Fetches the model if it has not been fetched before.

model.push([options])
  • options {Object} Options for the remote calls.
    • options.localStorage {Boolean} Whether or not use LocalStorage.

Pushes the changes performed to the model; create, update or destroy. In case you wish to distingish which call was finished in remote callbacks, an option "method" is passed.

model.push({
  success: function (model, response, options) {
    // options.method ["create"|"update"|"patch"|"destroy"]
  }
})
model.isFetched()

Returns 'true' if this model has been fetched remotely, 'false' otherwise.

model.dirtiedAttributes()

Retrieves a copy of the attributes that have changed since the last server synchronization.

model.hasDirtied([attr])
  • attr {String} The attribute to check if has been changed.

Returns 'true' in case the model changed since its last sever synchronization, 'false' otherwise.

model.isDirtyDestroyed()

Returns 'true' if this model has been destroyed locally, 'false' otherwise.

model.isDestroyed()

Returns 'true' if this model has been destroyed remotely, 'false' otherwise.

Compatibility and Requirements

  • jQuery
  • Underscore.js
  • Backbone
  • Backbone.Jsonify
  • Locally

Building and Testing

First install locally all the required development dependencies.

npm install

Building

grunt

Testing

grunt test

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

Read the CHANGELOG.md file distributed with the project.

License

Read the LICENSE file distributed with the project.

backbone.syncer's People

Contributors

nachocodoner 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.