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

@cicada/render

Package Overview
Dependencies
Maintainers
3
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.0.2 to 1.0.3

123

lib/connect.js

@@ -76,26 +76,2 @@ 'use strict';

function sortListeners() {
var listenerDef = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var defaultListener = arguments[1];
var _listenerDef$preventD = listenerDef.preventDefault,
preventDefault = _listenerDef$preventD === undefined ? false : _listenerDef$preventD,
_listenerDef$fns = listenerDef.fns,
listenerFns = _listenerDef$fns === undefined ? [] : _listenerDef$fns;
var finalListenerList = preventDefault !== true ? [defaultListener] : [];
listenerFns.forEach(function (_ref) {
var before = _ref.before,
fn = _ref.fn;
if (before === true) {
finalListenerList.unshift(fn);
} else {
finalListenerList.push(fn);
}
});
return finalListenerList;
}
function createIdentifierComponent(identifier) {

@@ -176,3 +152,2 @@ var Identifier = function Identifier() {

_this.setupDefaultListeners(defaultListeners);
// this.setupListeners(onChange, listeners, componentPath, isControlled)
_this.registerToContext(props, context, getInitialState);

@@ -239,23 +214,5 @@ return _this;

}, {
key: 'setupListeners',
value: function setupListeners(onChange, listeners, componentPath, isControlled) {
var _this3 = this;
this.listeners = (0, _util.mapValues)(defaultListeners, function (defaultListener, name) {
var changeFn = (0, _util.concat)(sortListeners(listeners[name], _this3.wrapDefaultListener(defaultListener, name)).map(function (listener) {
return (0, _util.inject)(listener, _this3.getInjectArg);
}));
return isControlled ? function () {
for (var _len = arguments.length, runtimeArgs = Array(_len), _key = 0; _key < _len; _key++) {
runtimeArgs[_key] = arguments[_key];
}
return onChange.apply(undefined, [changeFn, name, componentPath, _this3.getInjectArg.call(_this3)].concat(runtimeArgs));
} : changeFn;
});
}
}, {
key: 'setupIntercepters',
value: function setupIntercepters(intercepters) {
var _this4 = this;
var _this3 = this;

@@ -265,3 +222,3 @@ // 绑定 intercepter

this.intercepters = (0, _util.filter)((0, _util.mapValues)(defaultIntercepters, function (defaultIntercepter, name) {
return intercepters[name] !== undefined ? (0, _util.inject)(intercepters[name], _this4.getInjectArg) : defaultIntercepter === undefined ? undefined : (0, _util.inject)(defaultIntercepter, _this4.getRenderArg);
return intercepters[name] !== undefined ? (0, _util.inject)(intercepters[name], _this3.getInjectArg) : defaultIntercepter === undefined ? undefined : (0, _util.inject)(defaultIntercepter, _this3.getRenderArg);
}), function (i) {

@@ -274,14 +231,14 @@ return i !== undefined;

value: function setupDefaultListeners(listeners) {
var _this5 = this;
var _this4 = this;
this.listeners = (0, _util.mapValues)(listeners, function (defaultListener, name) {
return function () {
for (var _len2 = arguments.length, runtimeArgs = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
runtimeArgs[_key2] = arguments[_key2];
for (var _len = arguments.length, runtimeArgs = Array(_len), _key = 0; _key < _len; _key++) {
runtimeArgs[_key] = arguments[_key];
}
var statePath = _this5.getResolvedStatePath();
var nextState = defaultListener.apply(undefined, [_this5.getRenderArg(statePath)].concat(runtimeArgs));
var statePath = _this4.getResolvedStatePath();
var nextState = defaultListener.apply(undefined, [_this4.getRenderArg(statePath)].concat(runtimeArgs));
if (nextState !== undefined) {
_this5.context.stateTree.merge(_this5.getResolvedStatePath(), nextState, {
_this4.context.stateTree.merge(_this4.getResolvedStatePath(), nextState, {
type: _constant.REASON_DEFAULT_LISTENER,

@@ -341,3 +298,3 @@ source: name

value: function convertToControlledListener(injectedComponentArg) {
var _this6 = this;
var _this5 = this;

@@ -348,7 +305,7 @@ var listeners = (0, _util.mapValues)(injectedComponentArg.listeners, function (changeFn, name) {

for (var _len3 = arguments.length, runtimeArgs = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
runtimeArgs[_key3] = arguments[_key3];
for (var _len2 = arguments.length, runtimeArgs = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
runtimeArgs[_key2] = arguments[_key2];
}
return (_context = _this6.context).onChange.apply(_context, [changeFn, name, _this6.props.path].concat(runtimeArgs));
return (_context = _this5.context).onChange.apply(_context, [changeFn, name, _this5.props.path].concat(runtimeArgs));
};

@@ -401,16 +358,16 @@ });

var _initialiseProps = function _initialiseProps() {
var _this7 = this;
var _this6 = this;
this.getInjectArg = function () {
// CAUTION 一定要在运行时再拿path,因为 path 可能会变
var currentStatePath = _this7.getResolvedStatePath();
var stateTree = _this7.context.stateTree;
var appearance = _this7.context.appearance;
var currentStatePath = _this6.getResolvedStatePath();
var stateTree = _this6.context.stateTree;
var appearance = _this6.context.appearance;
return (0, _extends3.default)({
state: stateTree.get(currentStatePath),
statePath: new _common.StatePath(currentStatePath),
rootStatePath: new _common.StatePath(_this7.getResolvedRootPath()),
rootStatePath: new _common.StatePath(_this6.getResolvedRootPath()),
stateTree: stateTree,
appearance: appearance
}, _this7.context.background.instances);
}, _this6.context.background.instances);
};

@@ -421,9 +378,9 @@

return {
state: _this7.context.stateTree.get(statePath || _this7.getResolvedStatePath()),
props: _this7.props.props,
children: _this7.props.children,
listeners: _this7.listeners,
intercepters: _this7.intercepters,
context: _this7.context,
instance: _this7.instance
state: _this6.context.stateTree.get(statePath || _this6.getResolvedStatePath()),
props: _this6.props.props,
children: _this6.props.children,
listeners: _this6.listeners,
intercepters: _this6.intercepters,
context: _this6.context,
instance: _this6.instance
};

@@ -433,22 +390,22 @@ };

this.getResolvedStatePath = function () {
var reactContext = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this7.context;
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this7.props;
var reactContext = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this6.context;
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this6.props;
var _ref2 = reactContext || {},
_ref2$getScopes = _ref2.getScopes,
getScopes = _ref2$getScopes === undefined ? function () {
var _ref = reactContext || {},
_ref$getScopes = _ref.getScopes,
getScopes = _ref$getScopes === undefined ? function () {
return [];
} : _ref2$getScopes;
} : _ref$getScopes;
return (0, _common.resolveStatePath)(getScopes(), _this7.bind, props.scopeIndex);
return (0, _common.resolveStatePath)(getScopes(), _this6.bind, props.scopeIndex);
};
this.getResolvedRootPath = function () {
var _ref3 = _this7.context || {},
_ref3$getScopes = _ref3.getScopes,
getScopes = _ref3$getScopes === undefined ? function () {
var _ref2 = _this6.context || {},
_ref2$getScopes = _ref2.getScopes,
getScopes = _ref2$getScopes === undefined ? function () {
return [];
} : _ref3$getScopes;
} : _ref2$getScopes;
return (0, _common.resolveStatePath)(getScopes(), '', _this7.props.scopeIndex);
return (0, _common.resolveStatePath)(getScopes(), '', _this6.props.scopeIndex);
};

@@ -458,9 +415,9 @@

// CAUTION 在这里判断是因为未来 React 的 shouldComponentUpdate 会失效
if (shouldComponentUpdate === undefined || shouldComponentUpdate(_this7.getRenderArg(), type, changes) !== false) {
if (shouldComponentUpdate === undefined || shouldComponentUpdate(_this6.getRenderArg(), type, changes) !== false) {
// CAUTION 不要把 version 记录到 state 上,我们要确保的是 render,所以记到 render 上
_this7.setState({ stateChange: _this7.state.stateChange++ });
_this6.setState({ stateChange: _this6.state.stateChange++ });
}
// 新增的声明周期函数
if (type === _constant.CHANGE_STATETREE && typeof componentWillReceiveState === 'function') {
componentWillReceiveState(_this7.getRenderArg(), changes);
componentWillReceiveState(_this6.getRenderArg(), changes);
}

@@ -467,0 +424,0 @@ };

@@ -67,7 +67,9 @@ 'use strict';

function computeFrom(linkState, utilInstances) {
return (0, _util.mapValues)(linkState, function (_ref) {
var from = _ref.from;
function computeFrom(linkState, utilInstances, _ref) {
var state = _ref.state;
return from(utilInstances);
return (0, _util.mapValues)(linkState, function (_ref2) {
var from = _ref2.from;
return from((0, _extends3.default)({}, utilInstances, { state: state }));
});

@@ -77,4 +79,4 @@ }

function computeTo(linkState, state, utilInstances) {
(0, _util.each)(linkState, function (_ref2, name) {
var to = _ref2.to;
(0, _util.each)(linkState, function (_ref3, name) {
var to = _ref3.to;

@@ -94,5 +96,5 @@ to((0, _extends3.default)({ value: state[name], state: state }, utilInstances));

var configPath = configPathArr.join('.');
var exposeName = (0, _util.findIndex)(exposeListener, function (_ref3) {
var source = _ref3.source,
triggerListenerToMatch = _ref3.listener;
var exposeName = (0, _util.findIndex)(exposeListener, function (_ref4) {
var source = _ref4.source,
triggerListenerToMatch = _ref4.listener;
return source === configPath && triggerListener === triggerListenerToMatch;

@@ -154,4 +156,4 @@ });

var stateTypes = (0, _extends3.default)({}, (0, _util.mapValues)(linkState, function (_ref4) {
var stateType = _ref4.stateType;
var stateTypes = (0, _extends3.default)({}, (0, _util.mapValues)(linkState, function (_ref5) {
var stateType = _ref5.stateType;
return _propTypes2.default[stateType];

@@ -161,5 +163,5 @@ }));

var getDefaultState = function getDefaultState() {
return (0, _extends3.default)({}, (0, _util.mapValues)(linkState, function (_ref5) {
var getDefaultValue = _ref5.getDefaultValue,
stateType = _ref5.stateType;
return (0, _extends3.default)({}, (0, _util.mapValues)(linkState, function (_ref6) {
var getDefaultValue = _ref6.getDefaultValue,
stateType = _ref6.stateType;

@@ -172,3 +174,3 @@ /* eslint-disable no-prototype-builtins */

var commonListener = function commonListener(_ref6, _ref7) {
var commonListener = function commonListener(_ref7, _ref8) {
for (var _len2 = arguments.length, runtimeArgs = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {

@@ -178,5 +180,5 @@ runtimeArgs[_key2 - 2] = arguments[_key2];

var instance = _ref6.instance,
state = _ref6.state;
var changeFn = _ref7.changeFn;
var instance = _ref7.instance,
state = _ref7.state;
var changeFn = _ref8.changeFn;

@@ -207,5 +209,5 @@ if (changeFn === undefined) return state;

var componentWillReceiveProps = function componentWillReceiveProps(_ref8) {
var state = _ref8.state,
instance = _ref8.instance;
var componentWillReceiveProps = function componentWillReceiveProps(_ref9) {
var state = _ref9.state,
instance = _ref9.instance;

@@ -216,10 +218,10 @@ // CAUTION 注意,这里只针对外部引起的变化进行来重新内部render

var componentWillReceiveState = function componentWillReceiveState(_ref9, changes) {
var state = _ref9.state,
instance = _ref9.instance;
var componentWillReceiveState = function componentWillReceiveState(_ref10, changes) {
var state = _ref10.state,
instance = _ref10.instance;
// 如果改变是完全来自内部,那么就不用再计算 to 了
// 如果有一个改变时来自外部,那么要重新计算 to
if (changes.some(function (_ref10) {
var reason = _ref10.reason;
if (changes.some(function (_ref11) {
var reason = _ref11.reason;
return (typeof reason === 'undefined' ? 'undefined' : (0, _typeof3.default)(reason)) !== 'object' || reason.type !== _constant.REASON_DEFAULT_LISTENER;

@@ -237,2 +239,3 @@ })) {

instance.stateTreeVersion = stateTree.getVersion();
instance.state = state;
}

@@ -250,3 +253,3 @@

run: function run() {
return computeFrom(linkState, utilInstances);
return computeFrom(linkState, utilInstances, instance);
},

@@ -258,4 +261,4 @@ handle: function handle(_, result) {

},
check: function check(_ref11) {
var mockBackgroundJob = _ref11.mockBackgroundJob;
check: function check(_ref12) {
var mockBackgroundJob = _ref12.mockBackgroundJob;

@@ -274,7 +277,7 @@ return mockBackgroundJob === true;

componentWillReceiveState: componentWillReceiveState,
render: function render(_ref12) {
var listeners = _ref12.listeners,
instance = _ref12.instance,
state = _ref12.state,
context = _ref12.context;
render: function render(_ref13) {
var listeners = _ref13.listeners,
instance = _ref13.instance,
state = _ref13.state,
context = _ref13.context;

@@ -284,2 +287,4 @@ // CAUTION 始终只 render 一次,更新是依靠 componentWillReceiveState 实现的

instance.rendered = true;
// 存在 instance 上是因为 computeFrom 需要获取 state 作为参数
instance.state = state;

@@ -286,0 +291,0 @@ // 1. 要通过 preRender 的方式来得到完整的 stateTree

{
"name": "@cicada/render",
"version": "1.0.2",
"version": "1.0.3",
"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