mesh-envoy
Advanced tools
Comparing version 1.0.16 to 1.0.17
238
dist/dist.js
@@ -1,36 +0,3 @@ | ||
import { EMPTY_OBJ, NO_OP, isArray, isBrowser, isFunction, isNullOrUndef, isNumber, isUndefined, throwError } from 'mesh-envoy-shared'; | ||
import { EMPTY_OBJ, Lifecycle, NO_OP, isArray, isBrowser, isFunction, isNullOrUndef, isNumber, isStringOrNumber, isUndefined, throwError } from 'mesh-envoy-shared'; | ||
function createVNode() { | ||
return h$1.apply(undefined, arguments); | ||
} | ||
function push() { | ||
for (var _len = arguments.length, input = Array(_len), _key = 0; _key < _len; _key++) { | ||
input[_key] = arguments[_key]; | ||
} | ||
if (isFunction(input[0])) { | ||
render(createVNode.apply(undefined, input.concat([{}])), 'push'); | ||
} else { | ||
render.apply(undefined, input.concat(['push'])); | ||
} | ||
} | ||
function present() { | ||
for (var _len2 = arguments.length, input = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
input[_key2] = arguments[_key2]; | ||
} | ||
if (isFunction(input[0])) { | ||
render(createVNode.apply(undefined, input.concat([{}])), 'present'); | ||
} else { | ||
render.apply(undefined, input.concat(['present'])); | ||
} | ||
} | ||
var route = { | ||
push: push, | ||
present: present | ||
}; | ||
var toConsumableArray = function (arr) { | ||
@@ -59,2 +26,23 @@ if (Array.isArray(arr)) { | ||
function linkEvent(data, handler) { | ||
for (var _len = arguments.length, params = Array(_len > 2 ? _len - 2 : 0), _key2 = 2; _key2 < _len; _key2++) { | ||
params[_key2 - 2] = arguments[_key2]; | ||
} | ||
if (isFunction(handler)) { | ||
return function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key3 = 0; _key3 < _len2; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
handler.bind(data).apply(undefined, toConsumableArray(args.concat(params))); | ||
}; | ||
} else { | ||
if (process.env.NODE_ENV !== 'production') { | ||
throwError('a valid Component Event handler in linkEvent'); | ||
} | ||
throwError(); | ||
} | ||
} | ||
var nativeTags = { | ||
@@ -243,23 +231,2 @@ featurelist: { | ||
function linkEvent(data, handler) { | ||
for (var _len = arguments.length, params = Array(_len > 2 ? _len - 2 : 0), _key2 = 2; _key2 < _len; _key2++) { | ||
params[_key2 - 2] = arguments[_key2]; | ||
} | ||
if (isFunction(handler)) { | ||
return function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key3 = 0; _key3 < _len2; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
handler.bind(data).apply(undefined, toConsumableArray(args.concat(params))); | ||
}; | ||
} else { | ||
if (process.env.NODE_ENV !== 'production') { | ||
throwError('a valid Component Event handler in linkEvent'); | ||
} | ||
throwError(); | ||
} | ||
} | ||
function createElement(tagName) { | ||
@@ -282,2 +249,4 @@ return document.createElement(tagName); | ||
function insertBefore(parentNode, newNode, referenceNode) { | ||
// iOS Client Not Support Right Now | ||
throwError('Mesh is not suppot to insert Component Right Now. In list component you can use `hidden` attribute instead.'); | ||
patchQueue.push({ | ||
@@ -293,2 +262,4 @@ type: 'insert', | ||
function removeChild(node, child) { | ||
// iOS Client Not Support Right Now | ||
throwError('Mesh is not suppot to insert Component Right Now. In list component you can use `hidden` attribute instead.'); | ||
patchQueue.push({ | ||
@@ -1075,3 +1046,3 @@ type: 'remove', | ||
if (item.children) { | ||
item.children.forEach(function (childItem, i) { | ||
item.children.forEach(function (childItem) { | ||
if (isNullOrUndef(childItem)) { | ||
@@ -1187,2 +1158,35 @@ // item.children.splice(i, 1) | ||
function createVNode() { | ||
return h$1.apply(undefined, arguments); | ||
} | ||
function push() { | ||
for (var _len = arguments.length, input = Array(_len), _key = 0; _key < _len; _key++) { | ||
input[_key] = arguments[_key]; | ||
} | ||
if (isFunction(input[0])) { | ||
render(createVNode.apply(undefined, input.concat([{}])), 'push'); | ||
} else { | ||
render.apply(undefined, input.concat(['push'])); | ||
} | ||
} | ||
function present() { | ||
for (var _len2 = arguments.length, input = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
input[_key2] = arguments[_key2]; | ||
} | ||
if (isFunction(input[0])) { | ||
render(createVNode.apply(undefined, input.concat([{}])), 'present'); | ||
} else { | ||
render.apply(undefined, input.concat(['present'])); | ||
} | ||
} | ||
var route = { | ||
push: push, | ||
present: present | ||
}; | ||
function render(input) { | ||
@@ -1195,5 +1199,3 @@ var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'push'; | ||
// const result = mount(input, {}) | ||
document.body.innerHTML = ""; | ||
// const patchResult = patch(document.createElement('body'), result) | ||
var patchResult = createPatch(document.createElement('body'), input, {}); | ||
@@ -1209,7 +1211,7 @@ | ||
//TODO: Check VNode is Component and don't create instance if state,props don't update, just update the ref instance | ||
if (shouldPatch(Node.vNode, VNode)) { | ||
return patch(Node, mount(VNode, context)); | ||
if (shouldPatch(Node.instance, VNode)) { | ||
var input = mount(VNode, context); | ||
return patch(Node, input); | ||
} else { | ||
// TODO: new _lastInput | ||
return Node; | ||
return applyProps(Node.instance, VNode.data.attrs, context); | ||
} | ||
@@ -1219,19 +1221,59 @@ } | ||
function shouldPatch(vNode, newVNode) { | ||
if (!vNode || vNode.sel !== newVNode.sel) { | ||
if (!vNode || vNode.constructor.name !== newVNode.sel.name) { | ||
return true; | ||
} | ||
var keys = Object.keys(vNode.data); | ||
if (keys.length !== Object.keys(newVNode.data).length) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
for (var i = keys.length - 1; i >= 0; i--) { | ||
var key = keys[i]; | ||
var newValue = newVNode.data[key]; | ||
if (newValue !== vNode.data[key]) { | ||
return true; | ||
function applyProps(component, nextProps, context) { | ||
if (!component._blockRender && !component._unmounted) { | ||
var state = component.state; | ||
var props = component.props; | ||
var nextInput = component._undateComponent(state, state, props, nextProps, context, false, false); | ||
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(); | ||
} | ||
var lastInput = component._lastInput; | ||
if (didUpdate) { | ||
var subLifecycle = component._lifecycle; | ||
if (!subLifecycle) { | ||
subLifecycle = new Lifecycle(); | ||
} else { | ||
subLifecycle.listeners = []; | ||
} | ||
component._lifecycle = subLifecycle; | ||
var childContext = component.getChildContext(); | ||
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(nextProps, state); | ||
} | ||
} else { | ||
component.props = nextProps; | ||
} | ||
return false; | ||
return component.lastInput; | ||
} | ||
@@ -1256,2 +1298,3 @@ | ||
var instance = new Component(data.attrs, context); | ||
instance._blockSetState = false; | ||
instance._childNodes = children; | ||
@@ -1268,16 +1311,20 @@ instance.componentWillMount && instance.componentWillMount(); | ||
instance._vNode = input; | ||
instance._unmounted = false; | ||
instance._lastInput = mount(input, context); | ||
if (!instance._lastInput.vNode) { | ||
instance._lastInput.vNode = vNode; | ||
if (!instance._lastInput.instance) { | ||
instance._lastInput.instance = instance; | ||
instance._lastInput.data.hook = { | ||
remove: function remove(node, cb) { | ||
instance.componentWillUnmount && instance.componentWillUnmount(); | ||
delete MODULE_MAP[node.moduleId]; | ||
instance._unmounted = true; | ||
cb(); | ||
} | ||
}; | ||
} | ||
instance._lastInput.instance = instance; | ||
instance._lastInput.data.hook = { | ||
remove: function remove(node, cb) { | ||
instance.componentWillUnmount && instance.componentWillUnmount(); | ||
delete MODULE_MAP[node.moduleId]; | ||
instance._unmounted = true; | ||
cb(); | ||
} | ||
}; | ||
if (isFunction(instance.componentDidMount)) { | ||
instance.componentDidMount(); | ||
} | ||
return instance; | ||
@@ -1297,11 +1344,12 @@ } | ||
moduleId: dom.moduleId, | ||
attrs: dom.attrs | ||
attrs: dom.attrs, | ||
text: '' | ||
}; | ||
if (dom.childNodes) { | ||
if (isArray(dom.childNodes)) { | ||
result.childNodes = dom.childNodes.map(function (child) { | ||
if (!child.data) { | ||
if (isNullOrUndef(child.data)) { | ||
return stripDom(child); | ||
} else { | ||
result.text = child.data; | ||
result.text += child.data; | ||
} | ||
@@ -2025,5 +2073,11 @@ }); | ||
var globalObject = function () { | ||
return this; | ||
}(); | ||
var globalObject = void 0; | ||
if (process.env.NODE_ENV === 'test') { | ||
globalObject = global; | ||
} else { | ||
globalObject = function () { | ||
return this; | ||
}(); | ||
} | ||
globalObject.moduleId = 0; | ||
@@ -2030,0 +2084,0 @@ globalObject.GestureEventHandler = GestureEventHandler; |
{ | ||
"name": "mesh-envoy", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "", | ||
@@ -13,3 +13,3 @@ "main": "dist/dist.js", | ||
"build": "node ./build.js", | ||
"test": "BABEL_ENV=test jest --watch", | ||
"test": "NODE_ENV=test BABEL_ENV=test jest --watch", | ||
"flow": "flow" | ||
@@ -21,3 +21,3 @@ }, | ||
"dependencies": { | ||
"mesh-envoy-shared": "^1.0.7", | ||
"mesh-envoy-shared": "^1.0.17", | ||
"min-document": "^2.19.0", | ||
@@ -38,5 +38,8 @@ "snabbdom": "^0.6.6" | ||
"transformIgnorePatterns": [ | ||
"node_modules/(?!mesh-envoy-shared|mesh-envoy|mesh-envoy-dom)" | ||
] | ||
"node_modules/" | ||
], | ||
"moduleNameMapper": { | ||
"mesh-envoy-shared": "<rootDir>/node_modules/mesh-envoy-shared/dist/dist.js" | ||
} | ||
} | ||
} |
58679
1839
4
Updatedmesh-envoy-shared@^1.0.17