Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-subspace

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-subspace - npm Package Compare versions

Comparing version 2.3.1 to 2.4.0-0

es/index.js

617

lib/index.js
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, '__esModule', { value: true });
var _subspace = require('./store/subspace');
var redux = require('redux');
Object.defineProperty(exports, 'subspace', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_subspace).default;
}
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var _applyMiddleware = require('./store/applyMiddleware');
Object.defineProperty(exports, 'applyMiddleware', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_applyMiddleware).default;
}
});
var _namespaced = require('./reducers/namespaced');
Object.defineProperty(exports, 'namespaced', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_namespaced).default;
}
});
var _namespacedAction = require('./actions/namespacedAction');
Object.defineProperty(exports, 'namespacedAction', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_namespacedAction).default;
}
});
var _globalAction = require('./actions/globalAction');
Object.defineProperty(exports, 'globalAction', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_globalAction).default;
}
});
var _applyToRoot = require('./middleware/applyToRoot');
Object.defineProperty(exports, 'applyToRoot', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_applyToRoot).default;
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
});
var _applyToNamespaceRoots = require('./middleware/applyToNamespaceRoots');
return target;
};
Object.defineProperty(exports, 'applyToNamespaceRoots', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_applyToNamespaceRoots).default;
var objectWithoutProperties = function (obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
});
var _applyToChildren = require('./middleware/applyToChildren');
return target;
};
Object.defineProperty(exports, 'applyToChildren', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_applyToChildren).default;
}
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var applySubspaceMiddleware = function applySubspaceMiddleware() {
for (var _len = arguments.length, middlewares = Array(_len), _key = 0; _key < _len; _key++) {
middlewares[_key] = arguments[_key];
}
return function (createSubspace) {
return function (store) {
var subspacedStore = createSubspace(store);
var _getState = subspacedStore.getState,
_dispatch = subspacedStore.dispatch,
subscribe = subspacedStore.subscribe,
replaceReducer = subspacedStore.replaceReducer,
subspaceValues = objectWithoutProperties(subspacedStore, ['getState', 'dispatch', 'subscribe', 'replaceReducer']);
var middlewareApi = _extends({
getState: function getState() {
return _getState.apply(undefined, arguments);
},
dispatch: function dispatch() {
return _dispatch.apply(undefined, arguments);
}
}, subspaceValues);
var chain = middlewares.map(function (middleware) {
return middleware(middlewareApi);
}).map(function (pipeline) {
return typeof pipeline === 'function' ? { dispatch: pipeline } : pipeline;
});
var getStateChain = chain.map(function (pipeline) {
return pipeline.getState;
}).filter(function (pipeline) {
return pipeline;
});
var dispatchChain = chain.map(function (pipeline) {
return pipeline.dispatch;
}).filter(function (pipeline) {
return pipeline;
});
_getState = redux.compose.apply(undefined, getStateChain)(subspacedStore.getState);
_dispatch = redux.compose.apply(undefined, dispatchChain)(subspacedStore.dispatch);
return _extends({}, subspacedStore, {
getState: _getState,
dispatch: _dispatch
});
};
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var isGlobal = function isGlobal(action) {
return !action.type || action.globalAction === true;
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var namespacedAction = function namespacedAction(namespace) {
return function (action) {
return namespace && !isGlobal(action, namespace) ? _extends({}, action, { type: namespace + '/' + action.type }) : action;
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var copyProperties = function copyProperties(source, target) {
return Object.keys(source).forEach(function (key) {
return target[key] = source[key];
});
};
var scopedMiddleware = function scopedMiddleware(middleware, predicate) {
var wrappedMiddleware = function wrappedMiddleware(store) {
if (predicate(store)) {
var appliedMiddleware = middleware(store);
copyProperties(middleware, wrappedMiddleware);
return appliedMiddleware;
}
return {};
};
copyProperties(middleware, wrappedMiddleware);
return wrappedMiddleware;
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var ROOT = 'ROOT';
var NAMESPACE_ROOT = 'NAMESPACE_ROOT';
var CHILD = 'CHILD';
var subspaceTypesEnhancer = function subspaceTypesEnhancer(isRoot, namespace) {
return function (createSubspace) {
return function (store) {
var subspace = createSubspace(store);
var subspaceTypes = [];
if (isRoot) {
subspaceTypes.push(ROOT);
subspaceTypes.push(NAMESPACE_ROOT);
} else if (namespace) {
subspaceTypes.push(NAMESPACE_ROOT);
subspaceTypes.push(CHILD);
} else {
subspaceTypes.push(CHILD);
}
return _extends({}, subspace, { subspaceTypes: subspaceTypes });
};
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var childrenOnly = function childrenOnly(store) {
return store.subspaceTypes && store.subspaceTypes.indexOf(CHILD) >= 0;
};
var applyToChildren = function applyToChildren(middleware) {
return scopedMiddleware(middleware, childrenOnly);
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var verifyState = function verifyState(state) {
if (process.env.NODE_ENV !== 'production' && state === undefined) {
throw new TypeError('mapState must not return undefined.');
}
return state;
};
var subspaceEnhancer = function subspaceEnhancer(mapState, namespace) {
return applySubspaceMiddleware(applyToChildren(function (store) {
return {
getState: function getState(next) {
return function () {
return verifyState(mapState(next(), store.rootStore.getState()));
};
},
dispatch: function dispatch(next) {
return function (action) {
return next(namespacedAction(namespace)(action));
};
}
};
}));
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var namespaceEnhancer = function namespaceEnhancer(namespace) {
return function (createSubspace) {
return function (store) {
var subspace = createSubspace(store);
var parentNamespace = store.namespace || '';
var storeNamespace = void 0;
if (!namespace) {
storeNamespace = parentNamespace;
} else if (parentNamespace) {
storeNamespace = parentNamespace + '/' + namespace;
} else {
storeNamespace = namespace;
}
return _extends({}, subspace, { namespace: storeNamespace });
};
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var rootStoreEnhancer = function rootStoreEnhancer(createSubspace) {
return function (store) {
var subspace = createSubspace(store);
return _extends({}, subspace, { rootStore: store.rootStore || store });
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var hasNamespace = function hasNamespace(action, namespace) {
return action && action.type && action.type.indexOf(namespace + "/") === 0;
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var processAction = function processAction(namespace) {
return function (action, callback, defaultValue) {
if (!namespace || isGlobal(action)) {
return callback(action);
} else if (hasNamespace(action, namespace)) {
return callback(_extends({}, action, { type: action.type.substring(namespace.length + 1) }));
} else {
return defaultValue;
}
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var processActionEnhancer = function processActionEnhancer(namespace) {
return function (createSubspace) {
return function (store) {
var subspace = createSubspace(store);
return _extends({}, subspace, { processAction: processAction(namespace) });
};
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var resolveParameters = function resolveParameters(mapState, namespace) {
if (process.env.NODE_ENV !== 'production' && !(mapState || namespace)) {
throw new TypeError('mapState and/or namespace must be defined.');
}
var mapStateType = typeof mapState === 'undefined' ? 'undefined' : _typeof(mapState);
var namespaceType = typeof namespace === 'undefined' ? 'undefined' : _typeof(namespace);
if (mapStateType === 'string' && namespaceType !== 'null') {
namespace = mapState;
}
if (mapStateType !== 'function') {
mapState = function mapState(state) {
return state[namespace];
};
}
return [mapState, namespace];
};
var DEFAULT_OPTIONS = {
enhancer: function enhancer(subspace) {
return subspace;
}
};
var resolveEnhancer = function resolveEnhancer() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_OPTIONS,
_ref$enhancer = _ref.enhancer,
enhancer = _ref$enhancer === undefined ? DEFAULT_OPTIONS.enhancer : _ref$enhancer;
if (typeof enhancer !== 'function') {
if (process.env.NODE_ENV !== 'production') {
throw new TypeError('enhancer must be a function.');
}
return DEFAULT_OPTIONS.enhancer;
}
return enhancer;
};
var createSubspace = function createSubspace(store, enhancer) {
if (typeof enhancer !== 'undefined') {
return enhancer(createSubspace)(store);
}
return store;
};
var subspaceEnhanced = function subspaceEnhanced(mapState, namespace, isRoot) {
var subspaceEnhancers = redux.compose(subspaceEnhancer(mapState, namespace), namespaceEnhancer(namespace), subspaceTypesEnhancer(isRoot, namespace), processActionEnhancer(namespace), rootStoreEnhancer);
return function (store) {
return createSubspace(store, redux.compose(resolveEnhancer(store.subspaceOptions), subspaceEnhancers));
};
};
var subspaceRoot = function subspaceRoot(store, subspaceOptions) {
return subspaceEnhanced(undefined, undefined, true)(_extends({}, store, { subspaceOptions: subspaceOptions }));
};
var subspace = function subspace(mapState, namespace) {
return subspaceEnhanced.apply(undefined, resolveParameters(mapState, namespace));
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var applyMiddleware = function applyMiddleware() {
for (var _len = arguments.length, middlewares = Array(_len), _key = 0; _key < _len; _key++) {
middlewares[_key] = arguments[_key];
}
return function (createStore) {
return function (reducer, preloadedState, enhancer) {
var store = createStore(reducer, preloadedState, enhancer);
if (store.subspaceOptions && typeof store.subspaceOptions.enhancer === "function") {
return subspaceRoot(store, { enhancer: redux.compose(applySubspaceMiddleware.apply(undefined, middlewares), store.subspaceOptions.enhancer) });
}
return subspaceRoot(store, { enhancer: applySubspaceMiddleware.apply(undefined, middlewares) });
};
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var namespaced = (function (namespace) {
var actionProcessor = processAction(namespace);
return function (reducer) {
return function (state, action) {
if (typeof state === 'undefined') {
return reducer(state, action);
}
return actionProcessor(action, function (transformedAction) {
return reducer(state, transformedAction);
}, state);
};
};
});
var _globalActions = require('./middleware/globalActions');
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
Object.defineProperty(exports, 'globalActions', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_globalActions).default;
var globalAction = function globalAction(action) {
return action.type ? _extends({}, action, { globalAction: true }) : action;
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var rootOnly = function rootOnly(store) {
return !store.subspaceTypes || store.subspaceTypes.indexOf(ROOT) >= 0;
};
var applyToRoot = function applyToRoot(middleware) {
return scopedMiddleware(middleware, rootOnly);
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var namespaceRootsOnly = function namespaceRootsOnly(store) {
return !store.subspaceTypes || store.subspaceTypes.indexOf(NAMESPACE_ROOT) >= 0;
};
var applyToNamespaceRoots = function applyToNamespaceRoots(middleware) {
return scopedMiddleware(middleware, namespaceRootsOnly);
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
var isMatch = function isMatch(expectedType, actualType) {
return typeof expectedType === 'string' ? actualType === expectedType : actualType.match(expectedType) !== null;
};
var shouldBeGlobal = function shouldBeGlobal(action, actionTypes) {
return !isGlobal(action) && actionTypes.find(function (type) {
return isMatch(type, action.type);
});
};
var globalActions = function globalActions() {
for (var _len = arguments.length, actionTypes = Array(_len), _key = 0; _key < _len; _key++) {
actionTypes[_key] = arguments[_key];
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
return function (store) {
return function (next) {
return function (action) {
return shouldBeGlobal(action, actionTypes) ? store.dispatch(globalAction(action)) : next(action);
};
};
};
};
/**
* Copyright 2017, IOOF Holdings Limited.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
exports.subspace = subspace;
exports.applyMiddleware = applyMiddleware;
exports.namespaced = namespaced;
exports.namespacedAction = namespacedAction;
exports.globalAction = globalAction;
exports.applyToRoot = applyToRoot;
exports.applyToNamespaceRoots = applyToNamespaceRoots;
exports.applyToChildren = applyToChildren;
exports.globalActions = globalActions;

21

package.json
{
"name": "redux-subspace",
"version": "2.3.1",
"version": "2.4.0-0",
"description": "Create isolated subspaces of a Redux store",

@@ -12,9 +12,16 @@ "author": "Michael Peyper",

"main": "lib/index.js",
"typings": "lib/index.d.ts",
"module": "es/index.js",
"typings": "src/index.d.ts",
"sideEffects": false,
"files": [
"lib",
"es",
"src"
],
"scripts": {
"predist": "rimraf lib",
"dist": "babel src --out-dir lib --copy-files",
"predist": "rimraf lib es",
"dist": "rollup -c",
"lint": "eslint . --ext .js --ext .jsx",
"lint:fix": "eslint . --ext .js --ext .jsx --fix",
"test": "nyc mocha --compilers js:babel-register --require ./test/setup.js $(find test -name '*-spec.js')",
"test": "cross-env NODE_ENV=test nyc mocha --compilers js:babel-register --require ./test/setup.js $(find test -name '*-spec.js')",
"test:watch": "npm test -- --watch",

@@ -34,2 +41,3 @@ "prepublish": "npm run dist"

"babel-eslint": "^8.0.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.1",

@@ -40,2 +48,3 @@ "babel-preset-react": "^6.24.1",

"chai": "^4.1.2",
"cross-env": "^5.1.3",
"eslint": "^4.10.0",

@@ -49,2 +58,4 @@ "eslint-plugin-react": "^7.4.0",

"redux-thunk": "^2.2.0",
"rollup": "^0.55.5",
"rollup-plugin-babel": "^3.0.3",
"sinon": "^4.0.2",

@@ -51,0 +62,0 @@ "sinon-chai": "^2.14.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc