@instructure/redux-service-middleware

1.0.0 • Public • Published

@instructure/redux-service-middleware

npm MIT License

Simple redux middleware for registering service objects.

  1. A service is an object or class instance:
const myService = {
  doStuff: (arg1, arg2) => result
}
class MyOtherService {
  doOtherStuff (...args) {
    return result
  }
}
  1. While creating your store, register your services as key/value pairs with the service middleware constructor:
import { applyMiddleware } from 'redux'
import createServiceMiddleware from '@instructure/redux-service-middleware'

applyMiddleware(
  createServiceMiddleware({
    myKey: myService,
    myOtherKey: new MyOtherService()
  })
)
  1. In your action creator, dispatch an action with the following shape:
import { CALL_SERVICE } from '@instructure/redux-service-middleware'

const actionCreator = () => ({
  type: CALL_SERVICE,
  payload: {
    service: 'myKey',
    method: 'doStuff',
    args: [arg1, arg2]
  }
})

Calls to dispatch with an action of this form will return a promise resolving to the result of calling myService.methodName(arg1, arg2).

License

This project is is released under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i @instructure/redux-service-middleware

Weekly Downloads

839

Version

1.0.0

License

MIT

Unpacked Size

71.3 kB

Total Files

33

Last publish

Collaborators

  • bpjatacsuk
  • ajmal-esa
  • razorsh4rk
  • david.wenzlick.inst
  • robinkuss64
  • ardena
  • jcflow
  • jguardadom
  • jdewar
  • xcudder
  • ericsaupe
  • joyenjoyer
  • omarpr
  • cguanzon-inst
  • sarahgerard
  • jacksonhowe
  • jakeoeding
  • camray
  • cjs118
  • matyas.szabo
  • herrtopi
  • angela.gomba
  • kyler-instructure
  • instuici
  • eschiebel
  • maths22
  • jcrystal
  • skacsmark
  • itadmins
  • quizzesuici
  • instructure-toolsmiths-service-user
  • aogata-inst
  • instout