Git Product home page Git Product logo

redux-offline-sauce's Introduction

redux-offline-sauce

npm version Build Status

Some aesthetic toppings for your Redux Offline meal.

Installation

$ npm install --save redux-offline-sauce

Overview

What is Redux Offline? Redux Offline is a battle-tested offline-first architecture.

redux-offline-sauce inspired by reduxsauce aims to provide tools to work with Redux Offline.

Usage

createOfflineActions

Like createActions from reduxsauce, createOfflineActions returns Types and Creators.

When creating a new offline action, you most probably have written redux actions such as { type: 'DELETE_OBJ', id: 1} or redux thunk (id) => ({ type: 'UPDATE_OBJ', id: id }). createOfflineActions allows you to specify a redux action or redux thunk or mixture of both in commit and rollback of the offline action.

**Example: **

  const { Types, Creators } = createActions(NormalActionsConfig);
  const { Types: OfflineTypes, Creators: OfflineCreators } = createOfflineActions({
    createOfflineObj: {
      offline: Creators.createObj,
      effect: { url: '/api/create', method: 'POST', body: { a: 1, b: 2 } },
      commit: Creators.updateObj,
      rollback: Creators.deleteObj,
    },
    createOfflineObj2: {
      offline: Creators.createObj,
      effect: { url: '/api/create', method: 'POST', body: { a: 1, b: 2 } },
      commit: {
        action: Creators.updateObj,
        meta: ['id', { delay: 10, retries: 5 }],
      },
      rollback: { type: 'ROLLBACK', time: 'now', strategy: 'merge' },
      meta: {
        otherMeta: {
          a: 2,
          b: 3,
        },
      },
    },
  });

  OfflineTypes
  /*
    {
      CREATE_OFFLINE_OBJ: CREATE_OFFLINE_OBJ,
      CREATE_OFFLINE_OBJ2: CREATE_OFFLINE_OBJ2
    }
  */

  OfflineCreators.createOfflineObj(999, 'nine-nine-nine')
  /*
    {
      type: 'CREATE_OBJ',
      id: 999,
      name: 'nine-nine-nine',
      payload: { id: 999, name: 'nine-nine-nine' },
      meta: {
        offline: {
          effect: { url: '/api/create', method: 'POST', body: { id: 999, name: 'nine-nine-nine', a: 1, b: 2 } },
          commit: { type: 'UPDATE_OBJ', id: 999, name: 'nine-nine-nine', meta: {} },
          rollback: { type: 'DELETE_OBJ', id: 999, meta: {} },
        },
      }
    }
  */

  OfflineCreators.createOfflineObj2(999, 'nine-nine-nine')
  /*
    {
      type: 'CREATE_OBJ',
      id: 999,
      name: 'nine-nine-nine',
      payload: { id: 999, name: 'nine-nine-nine' },
      meta: {
        offline: {
          effect: { url: '/api/create', method: 'POST', body: { id: 999, name: 'nine-nine-nine', a: 1, b: 2 } },
          commit: { type: 'UPDATE_OBJ', id: 999, name: 'nine-nine-nine', meta: { id: 999, delay: 10, retries: 5 } },
          rollback: { type: 'ROLLBACK', time: 'now', strategy: 'merge' },
        },
        otherMeta: {
          a: 2,
          b: 3,
        },
      }
    }
  */

License

MIT

redux-offline-sauce's People

Contributors

tanhauhau avatar

Stargazers

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