Coder Social home page Coder Social logo

ember-data-offline's Introduction

Ember-data-offline

Build Status npm version Ember Observer Score Stories in Ready

Ember-data-offline is an addon that extends ember-data to work in offline mode.

It caches records in the local storage (IndexedDB or equivalents).

Installation

ember install ember-data-offline

Setup

First, define your application adapter with offline support:

//app/adapters/application.js

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

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

Then define a model and a serializer for it:

//app/serializers/application.js

import DS from 'ember-data';

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

If your primary key is different from 'id', you have to specify it in the adapter and serializer:

// in adapter:

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

For more information, please, take look at dummy app.

Details

All syncornizations between local storage and backend are queued and performed sequentially.

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-data-offline's Issues

Add better resolving for adapters/serializers

We need to provide resolving and registering for adapters/serailizers like regular ember app does, but also for offline ones, and maybe add some methods to store, like lookupOfflineAdapter.
This can look like that:

//app/adapters/application.js
var offline = LFAdapter.extend(offlineMixin, {...})
var online = RESTAdapter.extend(onlineMixin, {....})

export {offline, online}

Or add to app/adapters ...-offline adapters or separate offline folder from which we can resolve adpaters for offline.

Using regular id's

Hi,

I am trying to use this framework with an existing ember application. In an attempt to keep things simple of now, I want to just drop the framework in to the existing application but one of the things I am having trouble with is the use of id's. I understand that hash's are being used to avoid duplicates and sync errors across offline/online scenarios but is there any way to change this behaviour?

Where is this use of hashes for id's being dictated?

I realise I will need to change to use hashes for id's in the future, but for now I just want to get it working regardless of sync issues.

Any help you could provide is much appreciated, thanks.

Add persisting for failed requests

For now we have requests running in queue for retryCount times when failed.
But it is better to add some persistence for such failed reqs, that wasn't successful even after multiple times in queue.
If we'll do so, then consistency problem may appear.
To solve it without providing any additional uuid, etc. we can use git-like approach.
For example, we can provide some options in config like strategy: 'use-theirs/use-our' that will behave similar to git merge strategies.
To do so we can put all responsibility for changing data to both user and server.

Maintenance

Is this project still maintained?

It has errors with new version of ember. I'd like to know if someone plans to update it.

Solve problems with id consistance

смотри допустим ты и я работаем оффлайн оба. при этом локально у нас данные были одинаковые перед тем как мыы ушди в оффлайн, допустим юзеры с ид с 1 по 30. И вот я создаю юзера и ты. они локально получают разные идшки. у меня - mg1, у тебя - mg3. при этом создаются джобы, они крутятся там, потом появляется инет. допустим первым ранится твой джоб. на сервере создается новый юзер с ид 31. потом приходит мой реквест, создается юзер с ид 32. ну вроде как все норм, при файндАлл должно переписатсся, но у нас останутся дубликаты с ид mg1 и mg3 cоответсвенно. а еще при апдейте и делете веселей, когда допустим я удаляю юзера, потом ты удаляешь, а он уже удаленный на сервере

Issue with create new record

For now we replacing record, created by localforage with record from api, if api errored, we destroy record.

But in following scenario
createRecord -> save -> then transitionToRoute('...', savedRecord.id)
we go for route with id of localforage record, and then it replaced with record with id from api, and all operations in that route became invalid.

Maybe we need:

  • to check for connection while doing POST/PUT operation and if present do direct api request, and then sync it to offline

or

  • allow direct api request like with force option - store.createRecord('user', forceApi: true) and then sync as in example above

or

  • provide some callback from online job, to get moment when record in ember store is from api one

Create mixin for adapters

import offlineModeMixin from 'mixins/offline-mode';
import DS from 'ember-data';

export default DS.RESTAdapter.extend(offlineModeMixin, {

})

Issues installing addon.

Can't install addon.

ember install ember-data-offline
version: 1.13.0
Installed packages for tooling via npm.
installing ember-data-offline
The `ember generate` command requires an entity name to be specified. For more details, use `ember help`.

You must include an `id` for user in an object passed to `push`

Hi,
I am getting the following error when having the following in my route. Any idea how to solve the problem

Error: Assertion Failed: You must include an id for user in an object passed to push

export default Ember.Route.extend({
  model() {
      return this.store.findAll('member');
    },

Model

import DS from 'ember-data';
const { Model, attr, belongsTo } = DS;

export default Model.extend({
  memberId: attr('string'),
  user : belongsTo('user', {async: true}),

});

Serializer

import DS from 'ember-data';

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { 

  extractArray: function (store, type, payload) {

      //payload = { members: payload };

      console.log(payload.members);


    return this._super(store, type, payload);
  },

  attrs: {
    user: { embedded: 'always' },
  },

  extractSingle: function(store, typeClass, payload, id) {

    //payload = { member: payload };



    return this._super(store, typeClass, payload, id);
 }

});

Payload

{members:
[{"memberId":"123","id":9,
"user":{"id":24,"username":"member2","firstName":"member two","lastName":null}
],

Check for relations loading

  • check for loading in scenario like it is > 1000 records with > 2 belongsTo relations
  • check why it belongsTo/hasMany relation appear not immediately

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.