Comparing version 1.0.9 to 1.0.10
const isPlainObject = require('lodash/isPlainObject'); | ||
const merge = require('lodash/merge'); | ||
const assign = require('lodash/assign'); | ||
var server_regexp = /^@@server\/.*?$/i | ||
var defaultOptions = { | ||
next: false | ||
next: false, | ||
exclude: null | ||
} | ||
@@ -11,8 +12,10 @@ | ||
* Process client -> server dispatching | ||
* @param {Socket} io socket.io connection to server | ||
* @param {Object} options action processing options | ||
* @return {Mided} do not use it | ||
* @param {Socket} io - socket.io connection to server | ||
* @param {Object} options - action processing options | ||
* @param {Boolean} options.next - process server action or not | ||
* @param {Array} options.exclude - list of disallowed server action types | ||
* @return {Mided} - do not use it | ||
*/ | ||
module.exports = function getServerDispatchMiddleware(io, options) { | ||
let middlewareOptions = options ? merge(defaultOptions, options) : defaultOptions; | ||
let middlewareOptions = options ? assign(defaultOptions, options) : defaultOptions; | ||
@@ -25,6 +28,8 @@ return function () { | ||
if (server_regexp.test(action.type)) { | ||
if (middlewareOptions.next === false) { | ||
return io.emit('dispatch', action); | ||
} else { | ||
io.emit('dispatch', action); | ||
if (!middlewareOptions.exclude || middlewareOptions.exclude.indexOf(action.type) === -1) { | ||
if (middlewareOptions.next === false) { | ||
return io.emit('dispatch', action); | ||
} else { | ||
io.emit('dispatch', action); | ||
} | ||
} | ||
@@ -31,0 +36,0 @@ } |
{ | ||
"name": "redbone", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Polymorphic library for two way redux dispatching", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -57,4 +57,13 @@ # redbone | ||
`serverDispatchMiddleware` takes options as second parameter. If you want to pass server-side actions to store set `next` property as `true`, but if you want to exclude some actions from passing, set array of type to `exclude` property: | ||
``` | ||
middlewares.unshift(serverDispatchMiddleware(io, { | ||
next: true, | ||
exclude: [TYPES.EXCLUDED_TYPE, TYPES.EXCLUDED_TYPE_TOO] | ||
})); | ||
``` | ||
## Watchers | ||
documentation comming soon | ||
Look at server side example |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17983
401
69