react-cosmos-shared2
Advanced tools
Comparing version 4.7.0-12 to 4.7.0-13
@@ -8,15 +8,12 @@ "use strict"; | ||
}); | ||
exports.extractValuesFromObject = extractValuesFromObject; | ||
exports.extendObjectWithValues = extendObjectWithValues; | ||
exports.getPropsFixtureState = getPropsFixtureState; | ||
exports.updatePropsFixtureState = updatePropsFixtureState; | ||
exports.getStateFixtureState = getStateFixtureState; | ||
exports.updateStateFixtureState = updateStateFixtureState; | ||
exports.createFxStateMatcher = createFxStateMatcher; | ||
exports.createElFxStateMatcher = createElFxStateMatcher; | ||
exports.extractValuesFromObj = extractValuesFromObj; | ||
exports.extendObjWithValues = extendObjWithValues; | ||
exports.getCompFixtureStates = getCompFixtureStates; | ||
exports.findCompFixtureState = findCompFixtureState; | ||
exports.createCompFixtureState = createCompFixtureState; | ||
exports.updateCompFixtureState = updateCompFixtureState; | ||
exports.DEFAULT_RENDER_KEY = void 0; | ||
var _stringify = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/json/stringify")); | ||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty")); | ||
@@ -36,3 +33,3 @@ | ||
// Why store unserializable values in fixture state? | ||
var DEFAULT_RENDER_KEY = 0; // Why store unserializable values in fixture state? | ||
// - Because they still provides value in the Cosmos UI. They let the user know | ||
@@ -43,3 +40,6 @@ // that, eg. a prop, is present and see the read-only stringified value. | ||
// still be removed. | ||
function extractValuesFromObject(obj) { | ||
exports.DEFAULT_RENDER_KEY = DEFAULT_RENDER_KEY; | ||
function extractValuesFromObj(obj) { | ||
return (0, _keys.default)(obj) // Ignore noise from attrs defined as undefined (eg. props.children is | ||
@@ -55,3 +55,3 @@ // often `undefined` if element has no children) | ||
function extendObjectWithValues(obj, values) { | ||
function extendObjWithValues(obj, values) { | ||
return values.reduce(function (acc, _ref) { | ||
@@ -65,73 +65,80 @@ var serializable = _ref.serializable, | ||
function getPropsFixtureState(fixtureState, matcher) { | ||
if (!fixtureState || !fixtureState.props) { | ||
function getCompFixtureStates(fixtureState, decoratorId) { | ||
if (!fixtureState) { | ||
return []; | ||
} | ||
return matcher ? fixtureState.props.filter(matcher) : fixtureState.props; | ||
} | ||
var components = fixtureState.components; | ||
function updatePropsFixtureState(_ref2) { | ||
var fixtureState = _ref2.fixtureState, | ||
decoratorId = _ref2.decoratorId, | ||
elPath = _ref2.elPath, | ||
values = _ref2.values, | ||
_ref2$resetInstance = _ref2.resetInstance, | ||
resetInstance = _ref2$resetInstance === void 0 ? false : _ref2$resetInstance; | ||
var _getPropsFixtureState = getPropsFixtureState(fixtureState, function (i) { | ||
return i.decoratorId === decoratorId && i.elPath === elPath; | ||
}), | ||
_getPropsFixtureState2 = (0, _slicedToArray2.default)(_getPropsFixtureState, 1), | ||
propsFxState = _getPropsFixtureState2[0]; | ||
if (!propsFxState) { | ||
throw new Error("No props fixture state with decoratorId '".concat(decoratorId, "' and elPath '").concat(elPath, "'")); | ||
if (typeof decoratorId === 'undefined') { | ||
return components; | ||
} | ||
var renderKey = propsFxState.renderKey; | ||
return (0, _util.updateItem)(getPropsFixtureState(fixtureState), propsFxState, { | ||
renderKey: resetInstance ? renderKey + 1 : renderKey, | ||
values: values | ||
return components.filter(function (c) { | ||
return c.decoratorId === decoratorId; | ||
}); | ||
} | ||
function getStateFixtureState(fixtureState, matcher) { | ||
if (!fixtureState || !fixtureState.state) { | ||
return []; | ||
} | ||
function findCompFixtureState(fixtureState, decoratorId, elPath) { | ||
return (0, _lodash.find)(getCompFixtureStates(fixtureState), function (c) { | ||
return c.decoratorId === decoratorId && c.elPath === elPath; | ||
}); | ||
} | ||
return matcher ? fixtureState.state.filter(matcher) : fixtureState.state; | ||
function createCompFixtureState(_ref2) { | ||
var fixtureState = _ref2.fixtureState, | ||
decoratorId = _ref2.decoratorId, | ||
elPath = _ref2.elPath, | ||
componentName = _ref2.componentName, | ||
props = _ref2.props, | ||
state = _ref2.state; | ||
return (0, _util.replaceOrAddItem)(getCompFixtureStates(fixtureState), createFxStateMatcher(decoratorId, elPath), createCompFxState({ | ||
decoratorId: decoratorId, | ||
elPath: elPath, | ||
componentName: componentName, | ||
props: props, | ||
state: state | ||
})); | ||
} | ||
function updateStateFixtureState(_ref3) { | ||
function updateCompFixtureState(_ref3) { | ||
var fixtureState = _ref3.fixtureState, | ||
decoratorId = _ref3.decoratorId, | ||
elPath = _ref3.elPath, | ||
values = _ref3.values; | ||
props = _ref3.props, | ||
state = _ref3.state, | ||
_ref3$resetInstance = _ref3.resetInstance, | ||
resetInstance = _ref3$resetInstance === void 0 ? false : _ref3$resetInstance; | ||
var compFxState = findCompFixtureState(fixtureState, decoratorId, elPath); | ||
var _getStateFixtureState = getStateFixtureState(fixtureState, function (i) { | ||
return i.decoratorId === decoratorId && i.elPath === elPath; | ||
}), | ||
_getStateFixtureState2 = (0, _slicedToArray2.default)(_getStateFixtureState, 1), | ||
stateFxState = _getStateFixtureState2[0]; | ||
if (!stateFxState) { | ||
throw new Error("No state fixture state with decoratorId '".concat(decoratorId, "' and elPath '").concat(elPath, "'")); | ||
if (!compFxState) { | ||
throw new Error("[fixtureState] Component state not found for decoratorId \"".concat(decoratorId, "\" and elPath \"").concat(elPath, "\"")); | ||
} | ||
return (0, _util.updateItem)(getStateFixtureState(fixtureState), stateFxState, { | ||
values: values | ||
}); | ||
return (0, _util.updateItem)(getCompFixtureStates(fixtureState), compFxState, (0, _objectSpread3.default)({}, compFxState, { | ||
renderKey: resetInstance ? compFxState.renderKey + 1 : compFxState.renderKey, | ||
props: typeof props !== 'undefined' ? props : compFxState.props, | ||
state: typeof state !== 'undefined' ? state : compFxState.state | ||
})); | ||
} | ||
function createFxStateMatcher(decoratorId) { | ||
return function (fxState) { | ||
return fxState.decoratorId === decoratorId; | ||
function createCompFxState(_ref4) { | ||
var decoratorId = _ref4.decoratorId, | ||
elPath = _ref4.elPath, | ||
componentName = _ref4.componentName, | ||
props = _ref4.props, | ||
state = _ref4.state; | ||
return { | ||
decoratorId: decoratorId, | ||
elPath: elPath, | ||
componentName: componentName, | ||
renderKey: DEFAULT_RENDER_KEY, | ||
props: props, | ||
state: state | ||
}; | ||
} | ||
function createElFxStateMatcher(decoratorId, elPath) { | ||
return function (fxState) { | ||
return fxState.decoratorId === decoratorId && fxState.elPath === elPath; | ||
function createFxStateMatcher(decoratorId, elPath) { | ||
return function (s) { | ||
return s.decoratorId === decoratorId && s.elPath === elPath; | ||
}; | ||
@@ -142,3 +149,3 @@ } | ||
try { | ||
// XXX: Is this optimal? | ||
// NOTE: Is this optimal? | ||
if (!(0, _lodash.isEqual)(JSON.parse((0, _stringify.default)(value)), value)) { | ||
@@ -145,0 +152,0 @@ throw new Error('Unserializable value'); |
{ | ||
"name": "react-cosmos-shared2", | ||
"version": "4.7.0-12", | ||
"version": "4.7.0-13", | ||
"description": "Code shared between Cosmos packages", | ||
@@ -12,3 +12,3 @@ "repository": "https://github.com/react-cosmos/react-cosmos/tree/master/packages/react-cosmos-shared2", | ||
}, | ||
"gitHead": "b3e32f37be145d9c9be24646a4dada3072b8bbb0" | ||
"gitHead": "e2e906525a43357472a9674dc9b10d7d3ed65f5b" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
286
18417