@cicada/render
Advanced tools
Comparing version 1.1.7 to 1.1.8-alpha
@@ -289,2 +289,35 @@ 'use strict'; | ||
expect(container.html()).toEqual('<div><div>hide</div><div class="' + DISPLAY_NONE + '"></div></div>'); | ||
}); | ||
test('visible in primitve', function () { | ||
var container = (0, _enzyme.mount)(_react2.default.createElement(_Render2.default, { | ||
stateTree: stateTree, | ||
appearance: appearance, | ||
components: { Demo: (0, _connect2.default)(DemoComponent, 'Demo') }, | ||
background: (0, _createBackground2.default)({ | ||
jobs: { | ||
visible: visibilityJob | ||
}, | ||
utilities: { | ||
stateTree: stateTreeUtility | ||
} | ||
}, stateTree, appearance), | ||
config: { | ||
children: [{ | ||
bind: 'demo', | ||
type: 'Demo' | ||
}, { | ||
type: 'h3', | ||
visible: [function (_ref4) { | ||
var st = _ref4.stateTree; | ||
return st.get('demo').value !== 'hide'; | ||
}] | ||
}] | ||
} | ||
})); | ||
expect(container.html()).toEqual('<div><div></div><h3></h3></div>'); | ||
stateTree.set('demo', { value: 'hide' }); | ||
expect(container.html()).toEqual('<div><div>hide</div><h3 class="' + DISPLAY_NONE + '"></h3></div>'); | ||
}); |
@@ -26,6 +26,10 @@ 'use strict'; | ||
function register(stateId, _ref) { | ||
var className = _ref.className; | ||
var className = _ref.className, | ||
getStatePath = _ref.getStatePath; | ||
stateIdToClassNameFns[stateId] = typeof className === 'function' ? className : function () { | ||
return className; | ||
stateIdToClassNameFns[stateId] = { | ||
getStatePath: getStatePath, | ||
fn: typeof className === 'function' ? className : function () { | ||
return className; | ||
} | ||
}; | ||
@@ -36,5 +40,4 @@ } | ||
function run(stateId) { | ||
var state = stateTree.getById(stateId); | ||
var statePath = state._getStatePath(); | ||
return stateIdToClassNameFns[stateId]((0, _extends3.default)({}, utilInstances, { state: state, statePath: new _common.StatePath(statePath) })); | ||
var statePath = new _common.StatePath(stateIdToClassNameFns[stateId].getStatePath()); | ||
return stateIdToClassNameFns[stateId].fn((0, _extends3.default)({}, utilInstances, { statePath: statePath })); | ||
} | ||
@@ -41,0 +44,0 @@ |
@@ -40,3 +40,4 @@ 'use strict'; | ||
function register(stateId, _ref) { | ||
var style = _ref.style; | ||
var style = _ref.style, | ||
getStatePath = _ref.getStatePath; | ||
@@ -46,2 +47,3 @@ var styleName = appearance.createStylesheet(stateId, '{ }'); | ||
styleName: styleName, | ||
getStatePath: getStatePath, | ||
fn: typeof style === 'function' ? style : function () { | ||
@@ -56,5 +58,4 @@ return style; | ||
function run(stateId) { | ||
var state = stateTree.getById(stateId); | ||
var statePath = state._getStatePath(); | ||
return stateIdToStyleFns[stateId].fn((0, _extends3.default)({}, utilInstances, { state: state, statePath: new _common.StatePath(statePath) })); | ||
var statePath = new _common.StatePath(stateIdToStyleFns[stateId].getStatePath()); | ||
return stateIdToStyleFns[stateId].fn((0, _extends3.default)({}, utilInstances, { statePath: statePath })); | ||
} | ||
@@ -61,0 +62,0 @@ |
@@ -23,5 +23,6 @@ 'use strict'; | ||
var _ref$visible = _ref.visible, | ||
visible = _ref$visible === undefined ? [] : _ref$visible; | ||
visible = _ref$visible === undefined ? [] : _ref$visible, | ||
getStatePath = _ref.getStatePath; | ||
stateIdToVisibleFns[stateId] = visible; | ||
stateIdToVisibleFns[stateId] = { visibleArr: visible, getStatePath: getStatePath }; | ||
} | ||
@@ -31,5 +32,9 @@ | ||
function run(stateId) { | ||
var state = stateTree.getById(stateId); | ||
var statePath = state._getStatePath(); | ||
return stateIdToVisibleFns[stateId].every(function (v) { | ||
var _stateIdToVisibleFns$ = stateIdToVisibleFns[stateId], | ||
visibleArr = _stateIdToVisibleFns$.visibleArr, | ||
getStatePath = _stateIdToVisibleFns$.getStatePath; | ||
var statePath = getStatePath(); | ||
var state = stateTree.get(statePath); | ||
return visibleArr.every(function (v) { | ||
return v((0, _extends3.default)({}, utilInstances, { state: state, statePath: new _common.StatePath(statePath) })); | ||
@@ -36,0 +41,0 @@ }); |
@@ -48,8 +48,9 @@ 'use strict'; | ||
function getInjectArg(stateId) { | ||
var state = stateTree.getById(stateId); | ||
function getInjectArg(getStatePath) { | ||
var statePath = getStatePath(); | ||
var state = stateTree.get(statePath); | ||
return (0, _extends3.default)({ | ||
state: state, | ||
statePath: new _common.StatePath(state._getStatePath()), | ||
rootStatePath: new _common.StatePath(state._getRootStatePath()) | ||
statePath: new _common.StatePath(statePath), | ||
rootStatePath: new _common.StatePath(state && state._getRootStatePath ? state._getRootStatePath() : '') | ||
}, instances); | ||
@@ -59,3 +60,4 @@ } | ||
function register(stateId, _ref2) { | ||
var listeners = _ref2.listeners; | ||
var listeners = _ref2.listeners, | ||
getStatePath = _ref2.getStatePath; | ||
@@ -67,3 +69,3 @@ stateIdToListenerFactory[stateId] = (0, _util.mapValues)(listeners, function (listener) { | ||
return (0, _extends3.default)({}, listenerFnDef, { fn: (0, _util.inject)(listenerFnDef.fn, function () { | ||
return getInjectArg(stateId); | ||
return getInjectArg(getStatePath); | ||
}) }); | ||
@@ -70,0 +72,0 @@ }) |
@@ -90,14 +90,10 @@ 'use strict'; | ||
value: function render() { | ||
if (this.props.children === undefined) { | ||
if (this.props.children === undefined || this.props.children.length === 0) { | ||
throw new _errors.ErrorScopeChildren(0); | ||
} else if (Array.isArray(this.props.children) && this.props.children.length > 1) { | ||
throw new _errors.ErrorScopeChildren(this.props.children.length); | ||
} | ||
// react 16支持children为数组 | ||
return this.props.children; | ||
// 后面的 span 兼容的是文字模式, 不是指的数组, Scope 下不允许传数组 | ||
return _react2.default.isValidElement(this.props.children) ? this.props.children : _react2.default.createElement( | ||
'span', | ||
null, | ||
this.props.children | ||
); | ||
// return React.isValidElement(this.props.children) ? this.props.children : <span>{this.props.children}</span> | ||
} | ||
@@ -104,0 +100,0 @@ }]); |
@@ -7,6 +7,2 @@ 'use strict'; | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
@@ -32,2 +28,6 @@ | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
exports.default = createPrimitiveWrapper; | ||
@@ -45,2 +45,4 @@ | ||
var _common = require('./common'); | ||
var _constant = require('./constant'); | ||
@@ -55,6 +57,7 @@ | ||
var children = _ref.children, | ||
props = _ref.props; | ||
props = _ref.props, | ||
listeners = _ref.listeners; | ||
return _react2.default.createElement( | ||
Tag, | ||
props, | ||
(0, _extends3.default)({}, props, listeners), | ||
children | ||
@@ -75,7 +78,3 @@ ); | ||
_this.subscribe = function (type) { | ||
// appearance 采用ref去控制不再需要触发render | ||
if (type === _constant.CHANGE_APPEARANCE) return; | ||
_this.setState({ version: _this.state.version++ }); | ||
}; | ||
_initialiseProps.call(_this); | ||
@@ -97,4 +96,7 @@ _this.state = { | ||
}), {}), | ||
cancel = _background$register.cancel; | ||
cancel = _background$register.cancel, | ||
inject = _background$register.inject; | ||
_this.getStatePath = getStatePath; | ||
_this.inject = inject; | ||
_this.cancelBackground = cancel; | ||
@@ -115,3 +117,5 @@ return _this; | ||
value: function render() { | ||
return this.hijack(wrappedRender, display, this.props)((0, _extends3.default)({}, this.props)); | ||
var componentArg = this.getRenderArg(); | ||
var injectedComponentArg = this.inject(componentArg); | ||
return this.hijack(wrappedRender, display, this.props)(injectedComponentArg); | ||
} | ||
@@ -124,2 +128,3 @@ }]); | ||
Primitive.contextTypes = { | ||
stateTree: _propTypes2.default.object.isRequired, | ||
getStatePath: _propTypes2.default.func, | ||
@@ -130,4 +135,36 @@ background: _propTypes2.default.object.isRequired, | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.getInjectArg = function () { | ||
var currentStatePath = _this2.getStatePath(); | ||
var stateTree = _this2.context.stateTree; | ||
var appearance = _this2.context.appearance; | ||
return (0, _extends3.default)({ | ||
state: stateTree.get(currentStatePath), | ||
statePath: new _common.StatePath(currentStatePath), | ||
stateTree: stateTree, | ||
appearance: appearance | ||
}, _this2.context.background.instances); | ||
}; | ||
this.getRenderArg = function () { | ||
// 接受 statePath 为参数用来节约性能 | ||
return { | ||
props: _this2.props.props, | ||
children: _this2.props.children, | ||
listeners: _this2.props.listeners, | ||
context: _this2.context, | ||
inject: _this2.getInjectArg() | ||
}; | ||
}; | ||
this.subscribe = function (type) { | ||
// appearance 采用ref去控制不再需要触发render | ||
if (type === _constant.CHANGE_APPEARANCE) return; | ||
_this2.setState({ version: _this2.state.version++ }); | ||
}; | ||
}; | ||
return Primitive; | ||
} |
{ | ||
"name": "@cicada/render", | ||
"version": "1.1.7", | ||
"version": "1.1.8-alpha", | ||
"main": "./lib/index.js", | ||
@@ -17,4 +17,4 @@ "scripts": { | ||
"peerDependencies": { | ||
"react": ">=15.4.0", | ||
"react-dom": ">=15.4.0" | ||
"react": ">=16.0.0", | ||
"react-dom": ">=16.0.0" | ||
}, | ||
@@ -78,1 +78,2 @@ "babel": { | ||
} | ||
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
357322
64
8648
2