Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-fryctoria

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-fryctoria - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

blueprints/reopen-syncer-initializer/files/app/initializers/reopen-syncer.js

2

addon/stores/main-store/decorate-serializer.js

@@ -19,3 +19,3 @@ import isObject from '../../utils/is-object';

// normalize() is not used in localforage adapter, so we do not decorate
decorateSerializerMethod(serializer, localSerializer, 'serialize', 1);
decorateSerializerMethod(serializer, localSerializer, 'serialize', 0);
decorateSerializerMethod(serializer, localSerializer, 'extract', 2);

@@ -22,0 +22,0 @@ // decorateSerializerMethod(serializer, localSerializer, 'normalize', 2);

@@ -76,2 +76,3 @@ import Ember from 'ember';

var serializer = this.lookupStore('main').serializerFor(typeName);
snapshot.fryctoria = true;

@@ -180,5 +181,2 @@ return this.create('job', {

syncer.deleteAll('remoteIdRecord');
})
.then(function() {
Ember.Logger.info('Syncing succeed.');

@@ -190,4 +188,4 @@ })

Ember.Logger.info('Can not connect to server, stop syncing');
} else if(error === 'clear'){
return syncer.deleteAll('job');
} else if(syncer.handleSyncError){
return syncer.handleSyncError(error);
} else {

@@ -238,10 +236,3 @@ return RSVP.reject(error);

.then(createRemoteIdRecord)
.then(refreshLocalRecord)
.catch(function(error) {
if(syncer.syncErrorHandler) {
return syncer.syncErrorHandler(error);
} else {
return RSVP.reject(error);
}
});
.then(refreshLocalRecord);
}

@@ -248,0 +239,0 @@

{
"name": "ember-fryctoria",
"version": "0.1.5",
"version": "0.1.6",
"description": "Make ember data work offline with automatic sync.",

@@ -50,4 +50,4 @@ "directories": {

"configPath": "tests/dummy/config",
"defaultBlueprint": "application-store"
"defaultBlueprint": ["application-store", "reopen-syncer-initializer"]
}
}

@@ -6,3 +6,3 @@ # Warning

# Instruction
### Step1: Install the addon.
### Step1: Install the addons.
```bash

@@ -15,5 +15,4 @@ ember addon:install ember-localforage-adapter

# Requirements
ember-data v1.0.0-beta.16.x
ember-data v1.0.0-beta.16.1
# How does it work?

@@ -28,5 +27,22 @@ ember-fryctoria utilizes [ember-localforage-adapter](https://github.com/genkgo/ember-localforage-adapter/) to read and write locally.

**Features NOT supported(yet):**
- Sideloaded records are not saved to localforage automatically, only the main
records are saved.
- Changes in embeded records will not be pushed to server if you create or update offline
and try to sync when online. Only the main record will be updated or created.
# How to sync?
An object called *syncer* is responsible for syncing. In most cases, you do not need to manully sync since ember-fryctoria automatially syncUp(push local changes to remote server) before every request to server and automatially syncDown(save changes from remote server to localforage) after every request to server.
An object called *syncer* is responsible for syncing. It is registered into
container and you can get it via *container.lookup('main:syncer')*.
It has a *jobs* property whichs is a queue of operations including create, update and delete. These are your offline operations.
There are two important methods in *syncer*:
- syncUp: push local changes to remote server
- syncDown: save changes from remote server to localforage
In most cases, you do not need to manully sync since ember-fryctoria automatially syncUp before every request to server and automatially syncDown after every request to server.
However, when you sideload or embed records, you probably want to manully save sideloaded or embeded records to localforage. Also you may want to syncUp periodially. In these cases, you can manully syncDown or syncUp.

@@ -44,1 +60,27 @@

```
# How to handle errors during syncUp?
By default, when we get an error during syncUp, syncer will stop syncing. In the
next syncUp, syncer will try to start from the failed job. You can change this
behavior by adding a initializer and add a handleSyncError method in syncer.
The initializer *initializers/reopen-syncer.js* should already be created when you
install the addon via ember-cli. You can modify the handleSyncError method to
handle errors.
For example, you can remove all jobs when you get an error during syncUp. And
then restart your app by ```App.destroy()```,
since the outdated records in ember data store may create
errors when the user try to operate these records.
WARNING: This strategy will remove all the operations by user when he/her
was offline.
IMO, there is really not a single robust way to handle syncing faliure for
a conventional database like SQL combined with ember data. I would recommand you
to only enable user to read while offline. Or you should implement a robust way
to handle syncing errors for a specific app.
# How to decide what is offline?(Need implementation)
By default, whenever we have ```error.status === 0```, we define it as offline.
You can overwrite this behavior by overwriting *isOffline* method in the syncer.
Again, you can do this in reopen-syncer initializer.

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc