No description, website, or topics provided.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore
README.md
action-types.js
actions.js
constants.js
epic.js
example.js
index.js
package.json
updater.js

README.md

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

Dependencies

API

module = feathersAction(name)

module = feathersAction(options)

options:

  • name
  • methods
  • TODO idField

{ actions, updater, epic } = module

  • actions: object where keys are method names (find, get, create, ...)
  • updater: action => state => nextState
  • epic: (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.actions[method](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 --save

Acknowledgments

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

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