Code Monkey home page Code Monkey logo

sync's Introduction

Sync/Batcher for Angular

  • This is very much an alpha library *

Service to batch up offline requests and sync them with a server when possible.

Install

bower install Haemp/sync

Configure

flushInterval - how often we try to sync

angular.module('App').run(function(Sync, SyncOptions){

   // set options
   SyncOptions = {
      flushInterval: 9001
   }

   // start the automatic sync loop
   // this one syncs ever 9 seconds
   Sync.syncAuto();

   // OR do
   // to not have to set the options 
   // separatly
   Sync.syncAuto(9001);
});

Batching requests

Sync.batch({method:'GET', url: '/some/api', withCredentials:true});

[ ] Add httpInterceptor to batch all call automatically

Syncing requests

If you initiated the manuall loop the sync will handle itself. If you want to trigger it automatically:

Sync.syncManual();

Downsync (optional)

A normal sync process goes like this 1. User acts and generates a list of batched requests to be synced 2. Sync is triggered and the transactions merged into the server data 3. Client data is updated from the newly merged server data (downsync) The downsync is basically a poll of fresh server data that happens AFTER a sync operation is complete.

	SyncOptions.downsync = { 
		method: 'GET', 
		url: '/api/new/freshly/baked/data',
		withCredentials:true
	}

This request will be triggered after a full sync is successful. If the downsync process is interupted by another request by the user, it is cancelled and a new Sync process is started. This is to make sure the data you get back from the downsync is the latest merged server data.

Develop

git clone https://github.com/Haemp/sync
cd /sync
npm install
bower install

// testing
grunt test

sync's People

Contributors

haemp avatar

Watchers

 avatar  avatar

Forkers

azharweb

sync's Issues

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.