@cicada/render
Advanced tools
Comparing version 1.1.16-alpha2 to 1.1.16
@@ -195,3 +195,3 @@ 'use strict'; | ||
test('initStyle', function () { | ||
test('defaultStyle', function () { | ||
var runInFunc = false; | ||
@@ -214,5 +214,4 @@ var container = (0, _enzyme.mount)(_react2.default.createElement(_Render2.default, { | ||
type: 'Demo', | ||
initStyle: 'color: red;', | ||
defaultStyle: 'color: red;', | ||
style: function style() { | ||
// 第一次不会被执行 | ||
runInFunc = true; | ||
@@ -223,3 +222,3 @@ } | ||
})); | ||
expect(runInFunc).toEqual(false); | ||
expect(runInFunc).toEqual(true); | ||
expect(container.html()).toEqual('<div><div data-cicada-css-wq229y=""></div></div>'); | ||
@@ -226,0 +225,0 @@ }); |
@@ -42,3 +42,3 @@ 'use strict'; | ||
var style = _ref.style, | ||
initStyle = _ref.initStyle, | ||
defaultStyle = _ref.defaultStyle, | ||
getStatePath = _ref.getStatePath; | ||
@@ -48,3 +48,3 @@ | ||
getStatePath: getStatePath, | ||
initStyle: initStyle, | ||
defaultStyle: defaultStyle, | ||
firstRun: true, | ||
@@ -64,5 +64,5 @@ fn: typeof style === 'function' ? style : function () { | ||
// 返回初始化的style,这个方法用于style为模版函数时候需要保证样式在第一时间出现 | ||
if (stateIdToStyleFns[stateId].firstRun && stateIdToStyleFns[stateId].initStyle !== undefined) { | ||
if (stateIdToStyleFns[stateId].firstRun && stateIdToStyleFns[stateId].defaultStyle !== undefined) { | ||
stateIdToStyleFns[stateId].firstRun = false; | ||
return stateIdToStyleFns[stateId].initStyle; | ||
return stateIdToStyleFns[stateId].defaultStyle; | ||
} | ||
@@ -88,5 +88,5 @@ var statePath = new _common.StatePath(stateIdToStyleFns[stateId].getStatePath()); | ||
var style = _ref2.style, | ||
initStyle = _ref2.initStyle; | ||
defaultStyle = _ref2.defaultStyle; | ||
return typeof initStyle === 'string' || typeof style === 'string' || (typeof style === 'undefined' ? 'undefined' : (0, _typeof3.default)(style)) === 'object'; | ||
return typeof defaultStyle === 'string' || typeof style === 'string' || (typeof style === 'undefined' ? 'undefined' : (0, _typeof3.default)(style)) === 'object'; | ||
} | ||
@@ -93,0 +93,0 @@ |
@@ -24,5 +24,12 @@ 'use strict'; | ||
visible = _ref$visible === undefined ? [] : _ref$visible, | ||
_ref$defaultVisible = _ref.defaultVisible, | ||
defaultVisible = _ref$defaultVisible === undefined ? false : _ref$defaultVisible, | ||
getStatePath = _ref.getStatePath; | ||
stateIdToVisibleFns[stateId] = { visibleArr: typeof visible === 'function' ? [visible] : visible, getStatePath: getStatePath }; | ||
stateIdToVisibleFns[stateId] = { | ||
visibleArr: typeof visible === 'function' ? [visible] : visible, | ||
firstRun: true, | ||
defaultVisible: defaultVisible, // 默认值默认为false | ||
getStatePath: getStatePath | ||
}; | ||
return function () { | ||
@@ -37,4 +44,10 @@ delete stateIdToVisibleFns[stateId]; | ||
visibleArr = _stateIdToVisibleFns$.visibleArr, | ||
getStatePath = _stateIdToVisibleFns$.getStatePath; | ||
getStatePath = _stateIdToVisibleFns$.getStatePath, | ||
firstRun = _stateIdToVisibleFns$.firstRun, | ||
defaultVisible = _stateIdToVisibleFns$.defaultVisible; | ||
if (firstRun) { | ||
stateIdToVisibleFns[stateId].firstRun = false; | ||
return defaultVisible; | ||
} | ||
var statePath = getStatePath(); | ||
@@ -47,2 +60,7 @@ var state = stateTree.get(statePath); | ||
// visible在第一次都需要跑一遍,保证在初始化情况让组件可隐藏, 避免出现visible延迟设定导致的组件样式抖动 | ||
function shouldRunInRegister() { | ||
return true; | ||
} | ||
// 处理结果 | ||
@@ -56,3 +74,4 @@ function handle(stateId, result) { | ||
run: run, | ||
handle: handle | ||
handle: handle, | ||
shouldRunInRegister: shouldRunInRegister | ||
}; | ||
@@ -59,0 +78,0 @@ } |
@@ -235,2 +235,3 @@ 'use strict'; | ||
var content = render(componentArg); | ||
if (appearance[id].visible === false) styleList = styleList.concat(DISPLAY_NONE); | ||
if (styleList.length > 0 && content && content.props) { | ||
@@ -301,3 +302,3 @@ content = _react2.default.cloneElement(content, (0, _extends3.default)({}, content.props, styleList.reduce(function (res, key) { | ||
var componentPathKey = componentPath !== undefined ? componentPath.join('.') : undefined; | ||
appearance[id] = { visible: visible, styleList: [], lastStyleList: [], componentPath: componentPath | ||
appearance[id] = { visible: !!visible, styleList: [], lastStyleList: [], componentPath: componentPath | ||
// CAUTION 在与 react-router 这样的库结合使用时,由于会动态创建组件, | ||
@@ -304,0 +305,0 @@ // 所以 Render 无法给组件打上 path, 要兼容这种情况。 |
@@ -119,3 +119,2 @@ 'use strict'; | ||
run(stateId, name); | ||
return cancelFn; | ||
} | ||
@@ -122,0 +121,0 @@ // TODO 这样还是有问题的。 |
{ | ||
"name": "@cicada/render", | ||
"version": "1.1.16-alpha2", | ||
"version": "1.1.16", | ||
"main": "./lib/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
397925
9675
1