Skip to content

ShMcK/mirror-saga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mirror Saga

Adds Redux Sagas to Mirror.js.

NO LONGER MAINTAINED. MAY HAVE ISSUES.

Example

See a basic counter example.

Setup

Install dependencies.

npm install mirror-saga redux-saga

In your mirror setup, apply mirrorSaga.

import mirrorSaga from 'mirror-saga'

mirror.defaults(mirrorSaga())

// OR optionally pass in mirror default options
// mirror.defaults(mirrorSaga(options))

Use

Add model effects as generators (*function) and they will be treated as sagas by middleware.

// import saga effects from 'redux-saga' directly
import { delay } from 'redux-saga'

mirror.model({
  name: 'app',
  // ...
  effects: {
    *runASaga(payload) {
      yield delay(1000)
      yield actions.app.doSomething(payload)
    },
  }
})

Effects that are not generators will run normally using async/await.

import { call, take } from 'redux-saga'

const asyncDelay = (time) => new Promise((resolve, reject) => (
  setTimeout(() => resolve(), time))
)

export default {
  name: 'app',
  effects: {
    // runs as async function
    async effectExample() {
      await asyncDelay(1000)
      actions.app.increment()
    },
    // runs as saga
    *sagaExample() {
      yield take('authenticated')
      yield call(api, params)
      yield actions.app.increment()
    },
  }
}

About

Plugin to add Sagas to Mirror.js

Resources

Stars

Watchers

Forks

Packages

No packages published