reshow-return
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -28,9 +28,5 @@ "use strict"; | ||
var storeLocator = function storeLocator(props) { | ||
return props.stores; | ||
return props === null || props === void 0 ? void 0 : props.stores; | ||
}; | ||
var globalStoreLocator = function globalStoreLocator(props) { | ||
return null; | ||
}; | ||
var getMapIn = function getMapIn(map, path) { | ||
@@ -41,3 +37,3 @@ return map && map.getIn ? map.getIn(path) : undefined; | ||
var reset = function reset(props, more) { | ||
["immutable", "initStates", "pathStates", "stores", "storeLocator", "globalStoreLocator"].concat((0, _toConsumableArray2["default"])(more || [])).forEach(function (key) { | ||
["immutable", "initStates", "pathStates", "stores", "storeLocator"].concat((0, _toConsumableArray2["default"])(more || [])).forEach(function (key) { | ||
return delete props[key]; | ||
@@ -52,11 +48,10 @@ }); | ||
immutable: false, | ||
storeLocator: storeLocator, | ||
globalStoreLocator: globalStoreLocator | ||
storeLocator: storeLocator | ||
}; | ||
var getStores = function getStores(props) { | ||
return (0, _callFunc["default"])(props.storeLocator || storeLocator, [props]); | ||
return (0, _callFunc["default"])((props === null || props === void 0 ? void 0 : props.storeLocator) || storeLocator, [props]); | ||
}; | ||
var calculateState = function calculateState(prevState, props) { | ||
var calculateState = function calculateState(prevState, props, stores) { | ||
/** | ||
@@ -67,3 +62,3 @@ * Why not support multi stores? | ||
*/ | ||
var thisStore = (getStores(props) || [])[0]; | ||
var thisStore = (stores || [])[0]; | ||
@@ -76,12 +71,4 @@ if (!thisStore) { | ||
pathStates = props.pathStates, | ||
globalStoreLocator = props.globalStoreLocator, | ||
propsImmutable = props.immutable; | ||
var storeState = thisStore.getState(); | ||
var thisThemePath = storeState.get("themePath"); | ||
var globalStore = (0, _callFunc["default"])(globalStoreLocator, [props]); | ||
if (thisThemePath && globalStore && globalStore.path && globalStore.path !== thisThemePath) { | ||
return prevState; | ||
} | ||
var immutable = propsImmutable || storeState.get("immutable"); | ||
@@ -111,3 +98,3 @@ var results = {}; | ||
var thisPath = pathStates[key]; | ||
results[key] = immutable ? getMapIn((0, _getObjectValue["default"])(results, [thisPath[0]]), thisPath.slice(1)) : (0, _getObjectValue["default"])(results, thisPath); | ||
results[key] = immutable ? getMapIn(results[thisPath[0]], thisPath.slice(1)) : (0, _getObjectValue["default"])(results, thisPath); | ||
}); | ||
@@ -114,0 +101,0 @@ return results; |
"use strict"; | ||
var _interopRequireDefault = require("reshow-runtime/helpers/interopRequireDefault"); | ||
var _interopRequireWildcard = require("reshow-runtime/helpers/interopRequireWildcard"); | ||
var _interopRequireDefault = require("reshow-runtime/helpers/interopRequireDefault"); | ||
var _extends2 = _interopRequireDefault(require("reshow-runtime/helpers/extends")); | ||
@@ -33,15 +33,12 @@ | ||
var _Return = _interopRequireDefault(require("../Return")); | ||
var _Return2 = _interopRequireDefault(require("../Return")); | ||
var _div, _div2, _Return; | ||
(0, _enzyme.configure)({ | ||
adapter: new _enzymeAdapterReact["default"]() | ||
}); | ||
describe("Test Return", function () { | ||
var _FakeComponent, _FakeComponent2, _FakeComponent3, _FakeComponent4; | ||
var _ref = /*#__PURE__*/_react["default"].createElement("div", null); | ||
var _ref6 = /*#__PURE__*/_react["default"].createElement("div", null); | ||
var _ref7 = /*#__PURE__*/_react["default"].createElement(_Return["default"], null); | ||
describe("Test Return", function () { | ||
var TestEl = /*#__PURE__*/function (_PureComponent) { | ||
@@ -60,3 +57,3 @@ (0, _inherits2["default"])(TestEl, _PureComponent); | ||
value: function render() { | ||
return _ref; | ||
return _div || (_div = /*#__PURE__*/_react["default"].createElement("div", null)); | ||
} | ||
@@ -97,3 +94,3 @@ }]); | ||
var immutable = this.props.immutable; | ||
return /*#__PURE__*/_react["default"].createElement(_Return["default"], { | ||
return /*#__PURE__*/_react["default"].createElement(_Return2["default"], { | ||
stores: [_reshow.pageStore], | ||
@@ -116,2 +113,3 @@ immutable: immutable, | ||
var reset; | ||
var origConsoleError; | ||
beforeEach(function () { | ||
@@ -124,7 +122,5 @@ reset = (0, _jsdomGlobal["default"])(); | ||
}); | ||
it("assign props", function (done) { | ||
var vDom = _FakeComponent || (_FakeComponent = /*#__PURE__*/_react["default"].createElement(FakeComponent, null)); | ||
var _ref2 = /*#__PURE__*/_react["default"].createElement(FakeComponent, null); | ||
it("assign props", function (done) { | ||
var vDom = _ref2; | ||
var uFake = (0, _enzyme.mount)(vDom).instance(); | ||
@@ -150,11 +146,9 @@ (0, _reshow.dispatch)({ | ||
done(); | ||
}); | ||
}, 100); | ||
}); | ||
it("test Immutable path state", function (done) { | ||
var vDom = _FakeComponent2 || (_FakeComponent2 = /*#__PURE__*/_react["default"].createElement(FakeComponent, { | ||
immutable: true | ||
})); | ||
var _ref3 = /*#__PURE__*/_react["default"].createElement(FakeComponent, { | ||
immutable: true | ||
}); | ||
it("test Immutable path state", function (done) { | ||
var vDom = _ref3; | ||
var wrap = (0, _enzyme.mount)(vDom); | ||
@@ -189,15 +183,13 @@ var uFake = wrap.instance(); | ||
done(); | ||
}); | ||
}, 100); | ||
}); | ||
it("test path state should clean", function () { | ||
var vDom = _FakeComponent3 || (_FakeComponent3 = /*#__PURE__*/_react["default"].createElement(FakeComponent, { | ||
immutable: true | ||
})); | ||
var _ref4 = /*#__PURE__*/_react["default"].createElement(FakeComponent, { | ||
immutable: true | ||
}); | ||
var uFake = (0, _enzyme.mount)(vDom).instance(); | ||
var _ref5 = /*#__PURE__*/_react["default"].createElement(FakeComponent, null); | ||
var vDom1 = _FakeComponent4 || (_FakeComponent4 = /*#__PURE__*/_react["default"].createElement(FakeComponent, null)); | ||
it("test path state should clean", function () { | ||
var vDom = _ref4; | ||
var uFake = (0, _enzyme.mount)(vDom).instance(); | ||
var vDom1 = _ref5; | ||
var uFake1 = (0, _enzyme.mount)(vDom1).instance(); | ||
@@ -213,7 +205,7 @@ (0, _reshow.dispatch)({ | ||
var vDom = /*#__PURE__*/_react["default"].createElement(_Return["default"], { | ||
var vDom = /*#__PURE__*/_react["default"].createElement(_Return2["default"], { | ||
stores: [_reshow.pageStore], | ||
initStates: ["data"] | ||
}, function (props) { | ||
if (i) { | ||
if (i && props.data) { | ||
(0, _chai.expect)(props).to.deep.equal({ | ||
@@ -227,3 +219,3 @@ data: "foo" | ||
return _ref6; | ||
return _div2 || (_div2 = /*#__PURE__*/_react["default"].createElement("div", null)); | ||
}); | ||
@@ -235,11 +227,13 @@ | ||
}); | ||
setTimeout(function () { | ||
return wrap.unmount(); | ||
}); | ||
}); | ||
it("test store not defined", function () { | ||
origConsoleError = console.error; | ||
console.error = function () {}; | ||
(0, _chai.expect)(function () { | ||
(0, _enzyme.mount)(_ref7); | ||
(0, _enzyme.mount)(_Return || (_Return = /*#__PURE__*/_react["default"].createElement(_Return2["default"], null))); | ||
}).to["throw"](); | ||
console.error = origConsoleError; | ||
}); | ||
}); |
@@ -15,9 +15,5 @@ import _toConsumableArray from "reshow-runtime/es/helpers/toConsumableArray"; | ||
var storeLocator = function storeLocator(props) { | ||
return props.stores; | ||
return props === null || props === void 0 ? void 0 : props.stores; | ||
}; | ||
var globalStoreLocator = function globalStoreLocator(props) { | ||
return null; | ||
}; | ||
var getMapIn = function getMapIn(map, path) { | ||
@@ -28,3 +24,3 @@ return map && map.getIn ? map.getIn(path) : undefined; | ||
var reset = function reset(props, more) { | ||
["immutable", "initStates", "pathStates", "stores", "storeLocator", "globalStoreLocator"].concat(_toConsumableArray(more || [])).forEach(function (key) { | ||
["immutable", "initStates", "pathStates", "stores", "storeLocator"].concat(_toConsumableArray(more || [])).forEach(function (key) { | ||
return delete props[key]; | ||
@@ -39,11 +35,10 @@ }); | ||
immutable: false, | ||
storeLocator: storeLocator, | ||
globalStoreLocator: globalStoreLocator | ||
storeLocator: storeLocator | ||
}; | ||
var getStores = function getStores(props) { | ||
return callfunc(props.storeLocator || storeLocator, [props]); | ||
return callfunc((props === null || props === void 0 ? void 0 : props.storeLocator) || storeLocator, [props]); | ||
}; | ||
var calculateState = function calculateState(prevState, props) { | ||
var calculateState = function calculateState(prevState, props, stores) { | ||
/** | ||
@@ -54,3 +49,3 @@ * Why not support multi stores? | ||
*/ | ||
var thisStore = (getStores(props) || [])[0]; | ||
var thisStore = (stores || [])[0]; | ||
@@ -63,12 +58,4 @@ if (!thisStore) { | ||
pathStates = props.pathStates, | ||
globalStoreLocator = props.globalStoreLocator, | ||
propsImmutable = props.immutable; | ||
var storeState = thisStore.getState(); | ||
var thisThemePath = storeState.get("themePath"); | ||
var globalStore = callfunc(globalStoreLocator, [props]); | ||
if (thisThemePath && globalStore && globalStore.path && globalStore.path !== thisThemePath) { | ||
return prevState; | ||
} | ||
var immutable = propsImmutable || storeState.get("immutable"); | ||
@@ -98,3 +85,3 @@ var results = {}; | ||
var thisPath = pathStates[key]; | ||
results[key] = immutable ? getMapIn(get(results, [thisPath[0]]), thisPath.slice(1)) : get(results, thisPath); | ||
results[key] = immutable ? getMapIn(results[thisPath[0]], thisPath.slice(1)) : get(results, thisPath); | ||
}); | ||
@@ -101,0 +88,0 @@ return results; |
@@ -8,2 +8,5 @@ import _extends from "reshow-runtime/es/helpers/extends"; | ||
import _createSuper from "reshow-runtime/es/helpers/createSuper"; | ||
var _div, _div2, _Return; | ||
import React, { PureComponent } from "react"; | ||
@@ -19,10 +22,5 @@ import { pageStore, dispatch } from "reshow"; | ||
import Return from "../Return"; | ||
describe("Test Return", function () { | ||
var _FakeComponent, _FakeComponent2, _FakeComponent3, _FakeComponent4; | ||
var _ref = /*#__PURE__*/React.createElement("div", null); | ||
var _ref6 = /*#__PURE__*/React.createElement("div", null); | ||
var _ref7 = /*#__PURE__*/React.createElement(Return, null); | ||
describe("Test Return", function () { | ||
var TestEl = /*#__PURE__*/function (_PureComponent) { | ||
@@ -42,3 +40,3 @@ _inherits(TestEl, _PureComponent); | ||
value: function render() { | ||
return _ref; | ||
return _div || (_div = /*#__PURE__*/React.createElement("div", null)); | ||
} | ||
@@ -101,2 +99,3 @@ }]); | ||
var reset; | ||
var origConsoleError; | ||
beforeEach(function () { | ||
@@ -109,7 +108,5 @@ reset = jsdom(); | ||
}); | ||
it("assign props", function (done) { | ||
var vDom = _FakeComponent || (_FakeComponent = /*#__PURE__*/React.createElement(FakeComponent, null)); | ||
var _ref2 = /*#__PURE__*/React.createElement(FakeComponent, null); | ||
it("assign props", function (done) { | ||
var vDom = _ref2; | ||
var uFake = mount(vDom).instance(); | ||
@@ -135,11 +132,9 @@ dispatch({ | ||
done(); | ||
}); | ||
}, 100); | ||
}); | ||
it("test Immutable path state", function (done) { | ||
var vDom = _FakeComponent2 || (_FakeComponent2 = /*#__PURE__*/React.createElement(FakeComponent, { | ||
immutable: true | ||
})); | ||
var _ref3 = /*#__PURE__*/React.createElement(FakeComponent, { | ||
immutable: true | ||
}); | ||
it("test Immutable path state", function (done) { | ||
var vDom = _ref3; | ||
var wrap = mount(vDom); | ||
@@ -174,15 +169,13 @@ var uFake = wrap.instance(); | ||
done(); | ||
}); | ||
}, 100); | ||
}); | ||
it("test path state should clean", function () { | ||
var vDom = _FakeComponent3 || (_FakeComponent3 = /*#__PURE__*/React.createElement(FakeComponent, { | ||
immutable: true | ||
})); | ||
var _ref4 = /*#__PURE__*/React.createElement(FakeComponent, { | ||
immutable: true | ||
}); | ||
var uFake = mount(vDom).instance(); | ||
var _ref5 = /*#__PURE__*/React.createElement(FakeComponent, null); | ||
var vDom1 = _FakeComponent4 || (_FakeComponent4 = /*#__PURE__*/React.createElement(FakeComponent, null)); | ||
it("test path state should clean", function () { | ||
var vDom = _ref4; | ||
var uFake = mount(vDom).instance(); | ||
var vDom1 = _ref5; | ||
var uFake1 = mount(vDom1).instance(); | ||
@@ -201,3 +194,3 @@ dispatch({ | ||
}, function (props) { | ||
if (i) { | ||
if (i && props.data) { | ||
expect(props).to.deep.equal({ | ||
@@ -211,3 +204,3 @@ data: "foo" | ||
return _ref6; | ||
return _div2 || (_div2 = /*#__PURE__*/React.createElement("div", null)); | ||
}); | ||
@@ -218,11 +211,13 @@ var wrap = mount(vDom); | ||
}); | ||
setTimeout(function () { | ||
return wrap.unmount(); | ||
}); | ||
}); | ||
it("test store not defined", function () { | ||
origConsoleError = console.error; | ||
console.error = function () {}; | ||
expect(function () { | ||
mount(_ref7); | ||
mount(_Return || (_Return = /*#__PURE__*/React.createElement(Return, null))); | ||
}).to["throw"](); | ||
console.error = origConsoleError; | ||
}); | ||
}); |
{ | ||
"name": "reshow-return", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "reshow-return (simple connect component with reshow-flux)", | ||
@@ -5,0 +5,0 @@ "main": "./build/cjs/src/index.js", |
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
30023
16
866