New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mesh-envoy-component

Package Overview
Dependencies
Maintainers
1
Versions
203
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mesh-envoy-component - npm Package Compare versions

Comparing version 2.2.9 to 2.3.0

758

dist/dist.js

@@ -30,3 +30,3 @@ import { EMPTY_OBJ, ERROR_MSG, Lifecycle, NO_OP, isArray, isFunction, isNullOrUndef, isStringOrNumber, throwError } from 'mesh-envoy-shared';

if (process.env.NODE_ENV !== 'production') {
noOp = 'Envoy Error: Can only update a mounted or mounting component. This usually means you called setState() or forceUpdate() on an unmounted component. This is a no-op';
noOp = 'Envoy Error: Can only update a mounted or mounting component. This usually means you called setState() or forceUpdate() on an unmounted component. This is a no-op';
}

@@ -36,495 +36,339 @@

/**
* state 的更新队列
*
* @param {any} component
* @param {any} newState
* @param {any} callback
* @param {any} sync
*/
function queueStateChanges(component, newState, callback, sync) {
if (isFunction(newState)) {
newState = newState(component.state, component.props, component.context);
}
for (var stateKey in newState) {
component._pendingState[stateKey] = newState[stateKey];
}
if (isFunction(newState)) {
newState = newState(component.state, component.props, component.context);
}
for (var stateKey in newState) {
component._pendingState[stateKey] = newState[stateKey];
}
// 判断是否在更新 state 并且是不是需要直接更新
if (!component._pendingSetState && !(sync && component._blockRender)) {
if (sync || component._blockRender) {
// 直接更新
component._pendingSetState = true;
applyState(component, false, callback);
} else {
// 加入到更新队列
addToQueue(component, false, callback);
}
} else {
// 直接将 state 的值更新, 确保所有 pending state 全部更新
Object.assign(component.state, component._pendingState);
component._pendingState = {};
}
if (!component._pendingSetState && !(sync && component._blockRender)) {
if (sync || component._blockRender) {
component._pendingSetState = true;
applyState(component, false, callback);
} else {
addToQueue(component, false, callback);
}
} else {
Object.assign(component.state, component._pendingState);
component._pendingState = {};
}
}
/**
* 实际更新 state 方法
*
* @param {any} component
* @param {any} force
* @param {any} callback
*/
function applyState(component, force, callback) {
if ((!component._deferSetState || force) && !component._blockRender && !component._unmounted) {
component._pendingSetState = false;
var pendingState = component._pendingState;
var prevState = component.state;
var nextState = Object.assign({}, prevState, pendingState);
var props = component.props;
var context = component.context;
if ((!component._deferSetState || force) && !component._blockRender && !component._unmounted) {
component._pendingSetState = false;
var pendingState = component._pendingState;
var prevState = component.state;
var nextState = Object.assign({}, prevState, pendingState);
var props = component.props;
var context = component.context;
component._pendingState = {};
component._pendingState = {};
// 根据旧 state 和 新 state 对比更新
var nextInput = component._undateComponent(prevState, nextState, props, props, context, force, true);
var didUpdate = true;
var nextInput = component._undateComponent(prevState, nextState, props, props, context, force, true);
var didUpdate = true;
if (nextInput === NO_OP) {
// 没有变化操作
nextInput = component._lastInput;
didUpdate = false;
} else if (isStringOrNumber(nextInput)) {
// 变成了一个文本节点
nextInput = {
text: nextInput
};
} else if (isArray(nextInput)) {
if (process.env.NODE_ENV !== 'production') {
throwError('a valid Envoy VNode must be returned from a component render. You may have returned an array or an invalid object');
}
throwError();
}
if (nextInput === NO_OP) {
nextInput = component._lastInput;
didUpdate = false;
} else if (isStringOrNumber(nextInput)) {
nextInput = {
text: nextInput
};
} else if (isArray(nextInput)) {
if (process.env.NODE_ENV !== 'production') {
throwError('a valid Envoy VNode must be returned from a component render. You may have returned an array or an invalid object');
}
throwError();
}
var lastInput = component._lastInput;
var vNode = component._vNode;
var lastInput = component._lastInput;
var vNode = component._vNode;
if (didUpdate) {
// 更新生命周期时事件触发回调,暂时没用到
var subLifecycle = component._lifecycle;
if (didUpdate) {
var subLifecycle = component._lifecycle;
if (!subLifecycle) {
subLifecycle = new Lifecycle();
} else {
subLifecycle.listeners = [];
}
component._lifecycle = subLifecycle;
if (!subLifecycle) {
subLifecycle = new Lifecycle();
} else {
subLifecycle.listeners = [];
}
component._lifecycle = subLifecycle;
var childContext = component.getChildContext();
// context 对象的更新,组件树共享的对象
var childContext = component.getChildContext();
if (isNullOrUndef(childContext)) {
childContext = context;
} else {
childContext = Object.assign({}, context, component._childContext, childContext);
}
if (isNullOrUndef(childContext)) {
childContext = context;
} else {
childContext = Object.assign({}, context, component._childContext, childContext);
}
component._lastInput = component._patch(lastInput, nextInput, childContext);
subLifecycle.trigger();
component.excutePatchQueue();
component.componentDidUpdate(props, prevState);
}
// 将更新之后的 node 和之前 render 的 node 进行 patch ,push 到 patch 队列中
component._lastInput = component._patch(lastInput, nextInput, childContext);
subLifecycle.trigger();
// 执行 patch ,将更新推到客户端
component.excutePatchQueue();
component.componentDidUpdate(props, prevState);
}
if (nextInput && vNode) {
var dom = vNode.elm = nextInput.elm;
var componentToDOMNodeMap = component._componentToDOMNodeMap;
componentToDOMNodeMap && componentToDOMNodeMap.set(component, dom);
}
// component 和 dom 的索引,没有实际用到,后来都是使用 ref 方法在 component 中获取到 node
if (nextInput && vNode) {
var dom = vNode.elm = nextInput.elm;
var componentToDOMNodeMap = component._componentToDOMNodeMap;
componentToDOMNodeMap && componentToDOMNodeMap.set(component, dom);
}
if (!isNullOrUndef(callback)) {
// 调用 setState 的 callback
callback();
}
} else if (!isNullOrUndef(callback)) {
// 调用 setState 的 callback
callback();
}
if (!isNullOrUndef(callback)) {
/* $FlowPass */
callback();
}
} else if (!isNullOrUndef(callback)) {
/* $FlowPass */
callback();
}
}
/**
* 执行 state 更新队列, 简单的宏任务队列,当 eventloop 空闲是优先执行
*
* @param {any} component
* @param {any} force
* @param {any} callback
*/
function addToQueue(component, force, callback) {
var queue = componentCallbackQueue.get(component);
var queue = componentCallbackQueue.get(component);
if (!queue) {
queue = [];
componentCallbackQueue.set(component, queue);
Promise.resolve().then(function () {
componentCallbackQueue.delete(component);
applyState(component, force, function () {
for (var i = 0, len = queue.length; i < len; i++) {
queue[i]();
}
});
});
}
if (!queue) {
queue = [];
componentCallbackQueue.set(component, queue);
Promise.resolve().then(function () {
componentCallbackQueue.delete(component);
applyState(component, force, function () {
for (var i = 0, len = queue.length; i < len; i++) {
queue[i]();
}
});
});
}
if (callback) {
queue.push(callback);
}
if (callback) {
queue.push(callback);
}
}
var Component = function () {
// 该 component 的 child nodes
function Component(props, context) {
classCallCheck(this, Component);
Object.defineProperty(this, 'state', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, 'props', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, 'context', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, 'route', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, 'type', {
enumerable: true,
writable: true,
value: 'Component'
});
Object.defineProperty(this, '_blockRender', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_ignoreSetState', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_blockSetState', {
enumerable: true,
writable: true,
value: true
});
Object.defineProperty(this, '_deferSetState', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_pendingSetState', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_pendingState', {
enumerable: true,
writable: true,
value: {}
});
Object.defineProperty(this, '_lastInput', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_vNode', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_unmounted', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_lifecycle', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_childContext', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_childNodes', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_componentToDOMNodeMap', {
enumerable: true,
writable: true,
value: null
});
// Component 操作的回调,暂时没用到
this.props = props || {};
this.context = context || {};
}
// 用于 vode 的 ref ,暂时没用
createClass(Component, [{
key: 'forceUpdate',
value: function forceUpdate(callback) {
if (this._unmounted) {
return;
}
applyState(this, true, callback);
}
}, {
key: 'setState',
value: function setState(newState, callback) {
if (this._unmounted) {
return;
}
if (!this._blockSetState) {
if (!this._ignoreSetState) {
queueStateChanges(this, newState, callback, false);
}
} else {
if (process.env.NODE_ENV !== 'production') {
throwError('cannot update state via setState() in componentWillUpdate() or Constructor.');
}
throwError();
}
}
}, {
key: 'setStateSync',
value: function setStateSync(newState) {
if (this._unmounted) {
return;
}
if (!this._blockSetState) {
queueStateChanges(this, newState, null, true);
} else {
if (process.env.NODE_ENV !== 'production') {
throwError('cannot update state via setStateSync() in componentWillUpdate() or Constructor.');
}
throwError();
}
}
// 正在 pending 中的 state
/* eslint-disable no-unused-vars */
// 用于 applySetState
}, {
key: 'render',
value: function render(nextProps, nextState, nextContext) {}
}, {
key: 'componentWillMount',
value: function componentWillMount() {}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState, prevContext) {}
}, {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps, nextState, context) {
return true;
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps, context) {}
}, {
key: 'componentWillUpdate',
value: function componentWillUpdate(nextProps, nextState, nextContext) {}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {}
}, {
key: 'componentDidMount',
value: function componentDidMount() {}
// 忽略 setState
function Component(props, context) {
classCallCheck(this, Component);
Object.defineProperty(this, 'state', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, 'props', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, 'context', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, 'route', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, 'type', {
enumerable: true,
writable: true,
value: 'Component'
});
Object.defineProperty(this, '_blockRender', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_ignoreSetState', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_blockSetState', {
enumerable: true,
writable: true,
value: true
});
Object.defineProperty(this, '_deferSetState', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_pendingSetState', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_pendingState', {
enumerable: true,
writable: true,
value: {}
});
Object.defineProperty(this, '_lastInput', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_vNode', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_unmounted', {
enumerable: true,
writable: true,
value: false
});
Object.defineProperty(this, '_lifecycle', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_childContext', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_childNodes', {
enumerable: true,
writable: true,
value: null
});
Object.defineProperty(this, '_componentToDOMNodeMap', {
enumerable: true,
writable: true,
value: null
});
/* eslint-enable no-unused-vars */
this.props = props || {};
this.context = context || {};
}
}, {
key: 'getChildContext',
value: function getChildContext() {}
}, {
key: 'excutePatchQueue',
value: function excutePatchQueue() {}
}, {
key: '_patch',
value: function _patch() {}
}, {
key: '_undateComponent',
value: function _undateComponent(prevState, nextState, prevProps, nextProps, context, force, fromSetState) {
if (this._unmounted) {
if (process.env.NODE_ENV !== 'production') {
throwError(noOp);
}
throwError();
}
if (prevProps !== nextProps || nextProps === EMPTY_OBJ || prevState !== nextState || force) {
if (prevProps !== nextProps || nextProps === EMPTY_OBJ) {
if (!fromSetState) {
this._blockRender = true;
this.componentWillReceiveProps(nextProps, context);
this._blockRender = false;
}
if (this._pendingSetState) {
nextState = Object.assign({}, nextState, this._pendingState);
this._pendingSetState = false;
this._pendingState = {};
}
}
/**
* 强制更新
*
* @param {any} callback
* @memberof Component
*/
this.props = nextProps;
this.state = nextState;
this.context = context;
// compnent dom node ref, 暂时没用
var shouldUpdate = this.shouldComponentUpdate(nextProps, nextState, context);
// 该 component 子组件共享的 context object
if (shouldUpdate || force) {
this._blockSetState = true;
this.componentWillUpdate(nextProps, nextState, context);
this._blockSetState = false;
// 标记这个 Component 是否已经被删了
var render = this.render(nextProps, nextState, context);
// 上次输入的 node
return render;
}
}
// 标记是否在 setState
// 用于 componentWillUpdate
// 标记是否在 render
createClass(Component, [{
key: 'forceUpdate',
value: function forceUpdate(callback) {
if (this._unmounted) {
return;
}
applyState(this, true, callback);
}
/**
* 更新 state 方法
*
* @param {any} newState
* @param {any} callback
* @memberof Component
*/
}, {
key: 'setState',
value: function setState(newState, callback) {
if (this._unmounted) {
return;
}
if (!this._blockSetState) {
if (!this._ignoreSetState) {
// 加入更新队列
queueStateChanges(this, newState, callback, false);
}
} else {
if (process.env.NODE_ENV !== 'production') {
throwError('cannot update state via setState() in componentWillUpdate() or Constructor.');
}
throwError();
}
}
/**
* 同步更新 state 方法
*
* @param {any} newState
* @memberof Component
*/
}, {
key: 'setStateSync',
value: function setStateSync(newState) {
if (this._unmounted) {
return;
}
if (!this._blockSetState) {
queueStateChanges(this, newState, null, true);
} else {
if (process.env.NODE_ENV !== 'production') {
throwError('cannot update state via setStateSync() in componentWillUpdate() or Constructor.');
}
throwError();
}
}
/* eslint-disable no-unused-vars */
}, {
key: 'render',
value: function render(nextProps, nextState, nextContext) {}
/**
* 生命周期
*
* @memberof Component
*/
}, {
key: 'componentWillMount',
value: function componentWillMount() {}
/**
* 生命周期
*
* @memberof Component
*/
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState, prevContext) {}
/**
* 是否阻止更新
*
* @memberof Component
*/
}, {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate(nextProps, nextState, context) {
return true;
}
/**
* 生命周期
*
* @memberof Component
*/
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps, context) {}
/**
* 生命周期
*
* @memberof Component
*/
}, {
key: 'componentWillUpdate',
value: function componentWillUpdate(nextProps, nextState, nextContext) {}
/**
* 生命周期
*
* @memberof Component
*/
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {}
/**
* 生命周期
*
* @memberof Component
*/
}, {
key: 'componentDidMount',
value: function componentDidMount() {}
/* eslint-enable no-unused-vars */
/**
* 获取 context 方法,由需要使用到 childContext 的库去接入,比如 mobx
*
* @memberof Component
*/
}, {
key: 'getChildContext',
value: function getChildContext() {}
/**
* 有 mesh-envoy rendering 注入,发送给客户端
*
* @memberof Component
*/
}, {
key: 'excutePatchQueue',
value: function excutePatchQueue() {}
/**
* 有 mesh-envoy rendering 注入, diff 方法
*
* @memberof Component
*/
}, {
key: '_patch',
value: function _patch() {}
}, {
key: '_undateComponent',
value: function _undateComponent(prevState, nextState, prevProps, nextProps, context, force, fromSetState) {
if (this._unmounted) {
if (process.env.NODE_ENV !== 'production') {
throwError(noOp);
}
throwError();
}
if (prevProps !== nextProps || nextProps === EMPTY_OBJ || prevState !== nextState || force) {
if (prevProps !== nextProps || nextProps === EMPTY_OBJ) {
if (!fromSetState) {
this._blockRender = true;
this.componentWillReceiveProps(nextProps, context);
this._blockRender = false;
}
if (this._pendingSetState) {
nextState = Object.assign({}, nextState, this._pendingState);
this._pendingSetState = false;
this._pendingState = {};
}
}
this.props = nextProps;
this.state = nextState;
this.context = context;
// 先判断是不是不需要更新
var shouldUpdate = this.shouldComponentUpdate(nextProps, nextState, context);
if (shouldUpdate || force) {
this._blockSetState = true;
this.componentWillUpdate(nextProps, nextState, context);
this._blockSetState = false;
var render = this.render(nextProps, nextState, context);
return render;
}
}
return NO_OP;
}
}]);
return Component;
return NO_OP;
}
}]);
return Component;
}();
export default Component;
{
"name": "mesh-envoy-component",
"version": "2.2.9",
"description": "",
"main": "dist/dist.js",
"module": "src/index.js",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"dev": "nodemon --ignore dist build.js",
"build": "node ./build.js",
"build:pro": "NODE_ENV=production node ./build.js",
"test": "BABEL_ENV=test jest --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mesh-envoy": "^2.2.9",
"mesh-envoy-shared": "^2.2.4"
},
"devDependencies": {
"babel-eslint": "^7.1.1",
"babel-jest": "^19.0.0",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"eslint": "^3.16.1",
"eslint-plugin-flowtype": "^2.30.0",
"jest": "^19.0.2",
"rollup-plugin-terser": "^1.0.1"
},
"jest": {
"transformIgnorePatterns": [
"node_modules/"
],
"moduleNameMapper": {
"mesh-envoy-shared": "<rootDir>/node_modules/mesh-envoy-shared/dist/dist.js"
}
}
"name": "mesh-envoy-component",
"version": "2.3.0",
"description": "",
"main": "dist/dist.js",
"module": "src/index.js",
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"dev": "nodemon --ignore dist build.js",
"build": "node ./build.js",
"test": "BABEL_ENV=test jest --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mesh-envoy": "^2.3.0",
"mesh-envoy-shared": "^2.1.1"
},
"devDependencies": {
"babel-eslint": "^7.1.1",
"babel-jest": "^19.0.0",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0",
"eslint": "^3.16.1",
"eslint-plugin-flowtype": "^2.30.0",
"jest": "^19.0.2"
},
"jest": {
"transformIgnorePatterns": [
"node_modules/"
],
"moduleNameMapper": {
"mesh-envoy-shared": "<rootDir>/node_modules/mesh-envoy-shared/dist/dist.js"
}
}
}
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