Giter VIP home page Giter VIP logo

ember-data-offline's Introduction

Ember-data-offline

Build Status

Ember-data-offline is addon that provides some mixin that allows to achieve to main goals - to backup data, received from backend API to local storage to allow app to work in offline mode and to use this storage as a cache.

Installation

ember install ember-data-offline

Setup

First you need to define your application adapter:

import baseAdapter from 'ember-data-offline/adapters/base';

export default baseAdapter.extend({
  offlineNamespace: 'foo'//optional
});

Then specify model and define serializer for it (for now it is required, later we'll fix it):

import DS from 'ember-data';

export default DS.RESTSerializer.extend({
});

And basically, that's all!

If you have 'id' in your model different from default ('_id' for example), you need to specify it in adapter for the model like that:

export default appAdapter.extend({
  serializerPrimaryKey: '_id',
});

and also in serializer for that model you need to use mixin for translating it to normal 'id':

import DS from 'ember-data';
import offlineIdMixin from 'ember-data-offline/mixins/localstorage-id'; //thing that you need!

export default DS.RESTSerializer.extend(offlineIdMixin, {
  primaryKey: '_id', //usual ember-data stuff
});

Details

This addon contains of two essential parts. First - queue and jobs, second - online and offline mixins.

Queue is just super easy task runner and used to make kind of background proccessing mechanism and basically we use it to synchronize data flows from online api and local storage.

Online mixin redefine all adapter methods for finding, creation, deletion to to make request to online api, but with running offline job to make offline data actual.

Same for offline mixin, but vice versa.

As you see it is as simple as possible and names of mixins say mostly all about them :-).

Example of usage of these mixins you can see in addon/adapters/base.js.

Also we created this base adapter (addon/adapters/base.js) to simplify setup proccess. By default it use RESTAdapter and LocalForageAdapter, but you can use your own adapters that you like.

Contribution

  1. fork repo
  2. git clone [email protected]:your-github/ember-data-offline.git
  3. npm i && bower install
  4. add your feature
  5. cover with tests
  6. send PR!

License

[Licensed under MIT license] 1

ember-data-offline's People

Contributors

ember-tomster avatar igorrkurr avatar opakalex avatar pretender91 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.