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

@cicada/render

Package Overview
Dependencies
Maintainers
6
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cicada/render - npm Package Compare versions

Comparing version 1.1.13 to 1.1.14

lib/__test__/statePath.test.js

54

lib/__test__/convertFragment.test.js

@@ -49,2 +49,6 @@ 'use strict';

var _visibility = require('../background/job/visibility');
var visibilityJob = _interopRequireWildcard(_visibility);
var _applyStateTreeSubscriber = require('../applyStateTreeSubscriber');

@@ -481,2 +485,52 @@

test('visible in fragment', function () {
var fragment = {
config: {
type: 'Button',
bind: 'button',
visible: function visible(_ref12) {
var stateTree = _ref12.stateTree;
return stateTree.get('button.visible');
}
},
linkState: {
visible: {
from: function from(_ref13) {
var stateTree = _ref13.stateTree;
console.log('from...');
return stateTree.get('button.visible');
},
to: function to(_ref14) {
var value = _ref14.value;
return {
button: {
visible: value
}
};
},
getDefaultValue: function getDefaultValue() {
return true;
}
}
}
};
var Button = (0, _connect2.default)(ButtonComponent, 'Button');
var finalCreateTree = (0, _applyStateTreeSubscriber2.default)(_createStateTree2.default);
var ButtonFragment = (0, _connect2.default)((0, _convertFragment3.default)(fragment, finalCreateTree, _createAppearance2.default, _createBackground2.default, { utilities: { stateTree: stateTreeUtility }, jobs: { visible: visibilityJob } }), 'ButtonFragment');
var container = (0, _enzyme.mount)(_react2.default.createElement(_Render2.default, {
config: { type: 'ButtonFragment', bind: 'buttonFrag' },
components: { Button: Button, ButtonFragment: ButtonFragment },
stateTree: finalCreateTree()
}));
var store = container.instance().stateTree;
store.set('buttonFrag.visible', false);
expect(container.html()).toEqual('<button data-cicada-display-none="">0</button>');
store.set('buttonFrag.visible', true);
expect(container.html()).toEqual('<button>0</button>');
});
// TODO 补上 initialState, didMount

4

lib/background/job/visibility.js

@@ -26,3 +26,3 @@ 'use strict';

stateIdToVisibleFns[stateId] = { visibleArr: visible, getStatePath: getStatePath };
stateIdToVisibleFns[stateId] = { visibleArr: typeof visible === 'function' ? [visible] : visible, getStatePath: getStatePath };
return function () {

@@ -61,3 +61,3 @@ delete stateIdToVisibleFns[stateId];

return visible !== undefined && Array.isArray(visible) && visible.length !== 0;
return visible !== undefined && (typeof visible === 'function' || Array.isArray(visible) && visible.length !== 0);
}

@@ -117,3 +117,28 @@ 'use strict';

}
// 获得最接近有加bind的路径
}, {
key: 'relativeBind',
value: function relativeBind() {
var arr = this.toString().split('.');
// 这里用括号判断是不是引擎生成的bind
while (arr[arr.length - 1] !== undefined && /[()]/.test(arr[arr.length - 1])) {
arr.pop();
}
return new StatePath(arr.join('.'));
}
// 获得最接近的index
}, {
key: 'index',
value: function index() {
var arr = this.toString().split('.');
// 这里寻找最接近的索引
while (arr[arr.length - 1] !== undefined) {
if (/^[0-9]+$/.test(arr[arr.length - 1])) return Number(arr[arr.length - 1]);
arr.pop();
}
return 0;
}
}, {
key: 'explode',

@@ -120,0 +145,0 @@ value: function explode() {

@@ -7,2 +7,6 @@ 'use strict';

var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
var _assign = require('babel-runtime/core-js/object/assign');

@@ -12,6 +16,2 @@

var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
var _extends2 = require('babel-runtime/helpers/extends');

@@ -79,8 +79,13 @@

function computeTo(linkState, state, utilInstances) {
function computeTo(linkState, state, utilInstances, stateTree) {
var result = {};
(0, _util.each)(linkState, function (_ref3, name) {
var to = _ref3.to;
to((0, _extends3.default)({ value: state[name], state: state }, utilInstances));
(0, _assign2.default)(result, to((0, _extends3.default)({ value: state[name], state: state }, utilInstances)));
});
// 这里合并to的返回
(0, _util.each)(result, function (val, name) {
return stateTree.merge(name, val);
});
}

@@ -133,2 +138,5 @@

},
bool: function bool() {
return false;
},
array: function array() {

@@ -232,3 +240,3 @@ return [];

// CAUTION 注意,这里只针对外部引起的变化进行来重新内部render
computeTo(linkState, state, instance.background.instances);
computeTo(linkState, state, instance.background.instances, instance.stateTree);
if (willReceive) {

@@ -256,3 +264,3 @@ willReceive(instance.background.instances);

instance.background.pause();
computeTo(linkState, state, instance.background.instances);
computeTo(linkState, state, instance.background.instances, instance.stateTree);
instance.background.resume();

@@ -331,3 +339,3 @@ // CAUTION,只要是从外部接受过值,那么内外数据就一定一致,所以这里修正一下

// 启动的时候 computeTo 一次, 得到初始化好的 stateTree 和 background
computeTo(linkState, state, background.instances);
computeTo(linkState, state, background.instances, stateTree);
// 这个时候 stateTree 的初始值才真正设置进去

@@ -334,0 +342,0 @@ stateTree.unwrap();

@@ -69,3 +69,7 @@ 'use strict';

if (_constant.isDebug && _exist2.default.detect(stateTree, statePath) !== true) {
console.error('Warning: ' + new _errors.ErrorWrongStateTreePath(statePath, _exist2.default.detect(stateTree, statePath)));
var detectArr = _exist2.default.detect(stateTree, statePath);
// 只检测跳级搜索, 如搜a.b.c,但a.b不存在
if (statePath.split('.').length !== detectArr.length) {
console.error('Warning: ' + new _errors.ErrorWrongStateTreePath(statePath, detectArr.join('.')));
}
}

@@ -72,0 +76,0 @@

{
"name": "@cicada/render",
"version": "1.1.13",
"version": "1.1.14",
"main": "./lib/index.js",

@@ -5,0 +5,0 @@ "scripts": {

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