Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/instructure/service-middleware
ITSD-63375
https://github.com/instructure/service-middleware
Last synced: 8 days ago
JSON representation
ITSD-63375
- Host: GitHub
- URL: https://github.com/instructure/service-middleware
- Owner: instructure
- License: mit
- Created: 2020-01-31T23:17:18.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-18T20:49:50.000Z (over 1 year ago)
- Last Synced: 2024-04-14T20:26:08.041Z (7 months ago)
- Language: JavaScript
- Size: 1.63 MB
- Stars: 0
- Watchers: 9
- Forks: 2
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @instructure/redux-service-middleware
[![npm](https://img.shields.io/npm/v/@instructure/redux-service-middleware.svg)](https://www.npmjs.com/package/@instructure/redux-service-middleware)
[![MIT License](https://img.shields.io/npm/l/@instructure/redux-service-middleware.svg?style=flat-square)](https://github.com/instructure/redux-service-middleware/blob/master/LICENSE)Simple [redux](https://redux.js.org/) [middleware](https://redux.js.org/advanced/middleware/) for registering service objects.
1. A service is an object or class instance:
```javascript
const myService = {
doStuff: (arg1, arg2) => result
}
class MyOtherService {
doOtherStuff (...args) {
return result
}
}
```2. While creating your store, register your services as key/value pairs
with the service middleware constructor:```javascript
import { applyMiddleware } from 'redux'
import createServiceMiddleware from '@instructure/redux-service-middleware'applyMiddleware(
createServiceMiddleware({
myKey: myService,
myOtherKey: new MyOtherService()
})
)
```3. In your action creator, dispatch an action with the following shape:
```javascript
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) license.