feathers-action v2.4.0
feathers-action
never write another CRUD redux action!
this module helps you use feathers, redux, and tcomb.
Usage
const createModule = require('feathers-action')
const createCid = require('cuid')
const module = createModule('cats')
// module.actions
// module.epic
// module.updaterDependencies
feathers-reactive: must add plugin to feathers app / clientredux-observable: must add middleware to redux store
API
module = feathersAction(name)
module = feathersAction(options)
options:
namemethods- TODO
idField
{ actions, updater, epic } = module
actions: object where keys are method names (find,get,create, ...)updater:action => state => nextStateepic:(action, action$, store) => nextAction$
modules = feathersAction(name, ...)
modules = feathersAction(options, ...)
where modules is an object where key is name and value is module as above.
methodAction = module.actionsmethod(cid, ...args)
each action creator receives a cid (client-generated id) as the first argument.
all subsequent arguments for feathers methods are the same as the corresponding methods on the feathers service.
completeAction = module.actions.complete(cid)
cancels a long-running subscription as in find or get.
errorAction = module.actions.error(cid, err)
setAction = module.actions.set(cid, key, value)
sets the given key as value in the corresponding redux state.
to unset (remove key), value is undefined.
nextState = module.updater(action)(state)
see "updater" in redux-fp: action => state => nextState
nextAction$ = module.epic(action$, store, { feathers })
see "epic" in redux-observable: (action, action$, store) => nextAction$
must pass in { feathers } as deps to createEpicMiddleware
// client
const Feathers = require('feathers/client')
const feathersSockets = require('feathers-socketio/client')
const feathersRx = require('feathers-reactive')
const Rx = require('rxjs')
const socket = io()
const feathers = Feathers()
.configure(feathersSockets(socket))
.configure(feathersRx(Rx))
// store
const { createStore, applyMiddleware } = require('redux')
const { createEpicMiddleware } = require('redux-observable')
const rootEpic = require('./epic')
const rootUpdater = require('./updater')
const epicMiddleware = createEpicMiddleware(rootEpic, {
dependencies: { feathers }
})
const store = createStore(
(state, action) => rootUpdater(action)(state),
applyMiddleware(epicMiddleware)
)Install
With npm installed, run
$ npm install feathers-action --saveAcknowledgments
feathers-action was inspired by..
See Also
- redux
- feathers
License
The Apache License
Copyright © 2017 Michael Williams
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.