intact-react
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -97,3 +97,3 @@ 'use strict'; | ||
this.resolved = false; | ||
this.callback = undefined; | ||
this.callbacks = []; | ||
callback.call(this, function () { | ||
@@ -106,9 +106,12 @@ return _this.resolve(); | ||
this.resolved = true; | ||
this.callback && this.callback(); | ||
var cb = void 0; | ||
while (cb = this.callbacks.shift()) { | ||
cb(); | ||
} | ||
}; | ||
FakePromise.prototype.then = function then(cb) { | ||
this.callback = cb; | ||
this.callbacks.push(cb); | ||
if (this.resolved) { | ||
this.callback(); | ||
this.resolve(); | ||
} | ||
@@ -121,20 +124,48 @@ }; | ||
FakePromise.all = function (promises) { | ||
var count = promises.length; | ||
var resolvedCount = 0; | ||
var callback = void 0; | ||
var resolved = false; | ||
var done = false; | ||
promises.forEach(function (p) { | ||
p.then(function () { | ||
resolvedCount++; | ||
if (count === resolvedCount) { | ||
callback && callback(); | ||
} | ||
}); | ||
return p.then(then); | ||
}); | ||
if (promises._hasRewrite) { | ||
console.error('promises has not been done'); | ||
} | ||
var push = promises.push; | ||
promises.push = function (p) { | ||
p.then(then); | ||
push.call(promises, p); | ||
}; | ||
promises._hasRewrite = true; | ||
function _cb() { | ||
// clear array | ||
promises.length = 0; | ||
promises.push = push; | ||
promises._hasRewrite = false; | ||
callback(); | ||
} | ||
function then() { | ||
resolvedCount++; | ||
if (promises.length === resolvedCount) { | ||
resolved = true; | ||
if (done) { | ||
return console.error('promise has done'); | ||
} | ||
if (callback) { | ||
done = true; | ||
_cb(); | ||
} | ||
} | ||
} | ||
return { | ||
then: function then(cb) { | ||
callback = cb; | ||
if (!count) { | ||
callback(); | ||
if (!promises.length || resolved) { | ||
_cb(); | ||
} | ||
@@ -145,12 +176,2 @@ } | ||
var promises = []; | ||
var stacks = []; | ||
function pushStack() { | ||
stacks.push(promises); | ||
promises = []; | ||
} | ||
function popStack() { | ||
promises = stacks.pop(); | ||
} | ||
// wrap the react element to render it by react self | ||
@@ -195,2 +216,20 @@ | ||
var parentComponent = nextVNode.props.parentRef.instance; | ||
if (parentComponent) { | ||
if (!parentComponent._reactInternalFiber) { | ||
// is a firsthand intact component, get its parent instance | ||
parentComponent = parentComponent.get('parentRef').instance; | ||
} | ||
} else { | ||
// maybe the property which value is vNodes | ||
// find the closest IntactReact instance | ||
var parentVNode = nextVNode.parentVNode; | ||
while (parentVNode) { | ||
var children = parentVNode.children; | ||
if (children && children._reactInternalFiber !== undefined) { | ||
parentComponent = children; | ||
break; | ||
} | ||
parentVNode = parentVNode.parentVNode; | ||
} | ||
} | ||
var promise = new FakePromise(function (resolve) { | ||
@@ -203,3 +242,3 @@ if (parentComponent && parentComponent._reactInternalFiber !== undefined) { | ||
}); | ||
promises.push(promise); | ||
parentComponent.promises.push(promise); | ||
}; | ||
@@ -288,3 +327,3 @@ | ||
if (vNode.type && vNode.type.$$cid === 'IntactReact') { | ||
return h$1(vNode.type, normalizeProps(vNode.props, { _context: vNode._owner && vNode._owner.stateNode }, parentRef, vNode.key), null, null, vNode.key, vNode.ref); | ||
return h$1(vNode.type, normalizeProps(_extends({}, vNode.props, { parentRef: parentRef }), { _context: vNode._owner && vNode._owner.stateNode }, parentRef, vNode.key), null, null, vNode.key, vNode.ref); | ||
} | ||
@@ -429,4 +468,2 @@ | ||
var mountedQueue = void 0; | ||
var IntactReact = function (_Intact) { | ||
@@ -447,2 +484,5 @@ inherits(IntactReact, _Intact); | ||
_this.promises = context.promises || []; | ||
_this.mountedQueue = context.parent && context.parent.mountedQueue; | ||
// fake the vNode | ||
@@ -465,3 +505,4 @@ _this.vNode = h(_this.constructor, normalizedProps); | ||
return { | ||
parent: this | ||
parent: this, | ||
promises: this.promises | ||
}; | ||
@@ -510,23 +551,20 @@ }; | ||
IntactReact.prototype.init = function init() { | ||
var _Intact$prototype$ini, _Intact$prototype$ini2; | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
if (!this._isReact) return (_Intact$prototype$ini = _Intact.prototype.init).call.apply(_Intact$prototype$ini, [this].concat(args)); | ||
mountedQueue = this.mountedQueue; | ||
return (_Intact$prototype$ini2 = _Intact.prototype.init).call.apply(_Intact$prototype$ini2, [this].concat(args)); | ||
IntactReact.prototype.init = function init(lastVNode, nextVNode) { | ||
this.__pushGetChildContext(nextVNode); | ||
var element = _Intact.prototype.init.call(this, lastVNode, nextVNode); | ||
this.__popGetChildContext(); | ||
return element; | ||
}; | ||
IntactReact.prototype.update = function update() { | ||
var _Intact$prototype$upd, _Intact$prototype$upd2; | ||
IntactReact.prototype.update = function update(lastVNode, nextVNode, fromPending) { | ||
var _this2 = this; | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var update = function update() { | ||
_this2.__pushGetChildContext(nextVNode); | ||
var element = _Intact.prototype.update.call(_this2, lastVNode, nextVNode, fromPending); | ||
_this2.__popGetChildContext(); | ||
return element; | ||
}; | ||
if (!this._isReact) return (_Intact$prototype$upd = _Intact.prototype.update).call.apply(_Intact$prototype$upd, [this].concat(args)); | ||
if (!this._isReact) return update(); | ||
@@ -536,3 +574,3 @@ var oldTriggerFlag = this._shouldTrigger; | ||
var element = (_Intact$prototype$upd2 = _Intact.prototype.update).call.apply(_Intact$prototype$upd2, [this].concat(args)); | ||
var element = update(); | ||
@@ -545,4 +583,25 @@ this.__triggerMountedQueue(); | ||
IntactReact.prototype.__pushGetChildContext = function __pushGetChildContext(nextVNode) { | ||
var parentRef = nextVNode && nextVNode.props.parentRef; | ||
var parentInstance = parentRef && parentRef.instance; | ||
if (parentInstance) { | ||
var self = this; | ||
this.__getChildContext = parentInstance.getChildContext; | ||
parentInstance.getChildContext = function () { | ||
var context = self.__getChildContext.call(this); | ||
return _extends({}, context, { parent: self }); | ||
}; | ||
} | ||
this.__parentInstance = parentInstance; | ||
}; | ||
IntactReact.prototype.__popGetChildContext = function __popGetChildContext() { | ||
if (this.__parentInstance) { | ||
this.__parentInstance.getChildContext = this.__getChildContext; | ||
} | ||
}; | ||
IntactReact.prototype.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -573,3 +632,3 @@ var oldTriggerFlag = this._shouldTrigger; | ||
this.mountedQueue.push(function () { | ||
_this2.mount(); | ||
_this3.mount(); | ||
}); | ||
@@ -614,11 +673,13 @@ | ||
this._shouldTrigger = false; | ||
if (!mountedQueue || mountedQueue.done) { | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
// get from parent | ||
var tmp = void 0; | ||
if ((tmp = this.context) && (tmp = tmp.parent) && (tmp = tmp.mountedQueue)) { | ||
if (!tmp.done) { | ||
this.mountedQueue = tmp; | ||
return; | ||
} | ||
} | ||
this._shouldTrigger = true; | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
this._initMountedQueue(); | ||
} | ||
mountedQueue = this.mountedQueue; | ||
pushStack(); | ||
} else { | ||
this.mountedQueue = mountedQueue; | ||
this._initMountedQueue(); | ||
} | ||
@@ -628,14 +689,17 @@ }; | ||
IntactReact.prototype.__triggerMountedQueue = function __triggerMountedQueue() { | ||
var _this3 = this; | ||
var _this4 = this; | ||
if (this._shouldTrigger) { | ||
FakePromise.all(promises).then(function () { | ||
_this3._triggerMountedQueue(); | ||
FakePromise.all(this.promises).then(function () { | ||
_this4._triggerMountedQueue(); | ||
}); | ||
mountedQueue = null; | ||
this._shouldTrigger = false; | ||
popStack(); | ||
} | ||
}; | ||
IntactReact.prototype.__pushActiveInstance = function __pushActiveInstance() { | ||
var o = this._activeReactInstance; | ||
this._activeReactInstance = activeIntactReactInstance; | ||
}; | ||
createClass(IntactReact, [{ | ||
@@ -660,8 +724,10 @@ key: 'isMounted', | ||
_context: noop, | ||
parent: noop | ||
parent: noop, | ||
promises: noop | ||
}; | ||
IntactReact.childContextTypes = { | ||
parent: noop | ||
parent: noop, | ||
promises: noop | ||
}; | ||
module.exports = IntactReact; |
@@ -99,3 +99,3 @@ (function (global, factory) { | ||
this.resolved = false; | ||
this.callback = undefined; | ||
this.callbacks = []; | ||
callback.call(this, function () { | ||
@@ -108,9 +108,12 @@ return _this.resolve(); | ||
this.resolved = true; | ||
this.callback && this.callback(); | ||
var cb = void 0; | ||
while (cb = this.callbacks.shift()) { | ||
cb(); | ||
} | ||
}; | ||
FakePromise.prototype.then = function then(cb) { | ||
this.callback = cb; | ||
this.callbacks.push(cb); | ||
if (this.resolved) { | ||
this.callback(); | ||
this.resolve(); | ||
} | ||
@@ -123,20 +126,48 @@ }; | ||
FakePromise.all = function (promises) { | ||
var count = promises.length; | ||
var resolvedCount = 0; | ||
var callback = void 0; | ||
var resolved = false; | ||
var done = false; | ||
promises.forEach(function (p) { | ||
p.then(function () { | ||
resolvedCount++; | ||
if (count === resolvedCount) { | ||
callback && callback(); | ||
} | ||
}); | ||
return p.then(then); | ||
}); | ||
if (promises._hasRewrite) { | ||
console.error('promises has not been done'); | ||
} | ||
var push = promises.push; | ||
promises.push = function (p) { | ||
p.then(then); | ||
push.call(promises, p); | ||
}; | ||
promises._hasRewrite = true; | ||
function _cb() { | ||
// clear array | ||
promises.length = 0; | ||
promises.push = push; | ||
promises._hasRewrite = false; | ||
callback(); | ||
} | ||
function then() { | ||
resolvedCount++; | ||
if (promises.length === resolvedCount) { | ||
resolved = true; | ||
if (done) { | ||
return console.error('promise has done'); | ||
} | ||
if (callback) { | ||
done = true; | ||
_cb(); | ||
} | ||
} | ||
} | ||
return { | ||
then: function then(cb) { | ||
callback = cb; | ||
if (!count) { | ||
callback(); | ||
if (!promises.length || resolved) { | ||
_cb(); | ||
} | ||
@@ -147,12 +178,2 @@ } | ||
var promises = []; | ||
var stacks = []; | ||
function pushStack() { | ||
stacks.push(promises); | ||
promises = []; | ||
} | ||
function popStack() { | ||
promises = stacks.pop(); | ||
} | ||
// wrap the react element to render it by react self | ||
@@ -197,2 +218,20 @@ | ||
var parentComponent = nextVNode.props.parentRef.instance; | ||
if (parentComponent) { | ||
if (!parentComponent._reactInternalFiber) { | ||
// is a firsthand intact component, get its parent instance | ||
parentComponent = parentComponent.get('parentRef').instance; | ||
} | ||
} else { | ||
// maybe the property which value is vNodes | ||
// find the closest IntactReact instance | ||
var parentVNode = nextVNode.parentVNode; | ||
while (parentVNode) { | ||
var children = parentVNode.children; | ||
if (children && children._reactInternalFiber !== undefined) { | ||
parentComponent = children; | ||
break; | ||
} | ||
parentVNode = parentVNode.parentVNode; | ||
} | ||
} | ||
var promise = new FakePromise(function (resolve) { | ||
@@ -205,3 +244,3 @@ if (parentComponent && parentComponent._reactInternalFiber !== undefined) { | ||
}); | ||
promises.push(promise); | ||
parentComponent.promises.push(promise); | ||
}; | ||
@@ -290,3 +329,3 @@ | ||
if (vNode.type && vNode.type.$$cid === 'IntactReact') { | ||
return h$1(vNode.type, normalizeProps(vNode.props, { _context: vNode._owner && vNode._owner.stateNode }, parentRef, vNode.key), null, null, vNode.key, vNode.ref); | ||
return h$1(vNode.type, normalizeProps(_extends({}, vNode.props, { parentRef: parentRef }), { _context: vNode._owner && vNode._owner.stateNode }, parentRef, vNode.key), null, null, vNode.key, vNode.ref); | ||
} | ||
@@ -431,4 +470,2 @@ | ||
var mountedQueue = void 0; | ||
var IntactReact = function (_Intact) { | ||
@@ -449,2 +486,5 @@ inherits(IntactReact, _Intact); | ||
_this.promises = context.promises || []; | ||
_this.mountedQueue = context.parent && context.parent.mountedQueue; | ||
// fake the vNode | ||
@@ -467,3 +507,4 @@ _this.vNode = h(_this.constructor, normalizedProps); | ||
return { | ||
parent: this | ||
parent: this, | ||
promises: this.promises | ||
}; | ||
@@ -512,23 +553,20 @@ }; | ||
IntactReact.prototype.init = function init() { | ||
var _Intact$prototype$ini, _Intact$prototype$ini2; | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
if (!this._isReact) return (_Intact$prototype$ini = _Intact.prototype.init).call.apply(_Intact$prototype$ini, [this].concat(args)); | ||
mountedQueue = this.mountedQueue; | ||
return (_Intact$prototype$ini2 = _Intact.prototype.init).call.apply(_Intact$prototype$ini2, [this].concat(args)); | ||
IntactReact.prototype.init = function init(lastVNode, nextVNode) { | ||
this.__pushGetChildContext(nextVNode); | ||
var element = _Intact.prototype.init.call(this, lastVNode, nextVNode); | ||
this.__popGetChildContext(); | ||
return element; | ||
}; | ||
IntactReact.prototype.update = function update() { | ||
var _Intact$prototype$upd, _Intact$prototype$upd2; | ||
IntactReact.prototype.update = function update(lastVNode, nextVNode, fromPending) { | ||
var _this2 = this; | ||
for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
} | ||
var update = function update() { | ||
_this2.__pushGetChildContext(nextVNode); | ||
var element = _Intact.prototype.update.call(_this2, lastVNode, nextVNode, fromPending); | ||
_this2.__popGetChildContext(); | ||
return element; | ||
}; | ||
if (!this._isReact) return (_Intact$prototype$upd = _Intact.prototype.update).call.apply(_Intact$prototype$upd, [this].concat(args)); | ||
if (!this._isReact) return update(); | ||
@@ -538,3 +576,3 @@ var oldTriggerFlag = this._shouldTrigger; | ||
var element = (_Intact$prototype$upd2 = _Intact.prototype.update).call.apply(_Intact$prototype$upd2, [this].concat(args)); | ||
var element = update(); | ||
@@ -547,4 +585,25 @@ this.__triggerMountedQueue(); | ||
IntactReact.prototype.__pushGetChildContext = function __pushGetChildContext(nextVNode) { | ||
var parentRef = nextVNode && nextVNode.props.parentRef; | ||
var parentInstance = parentRef && parentRef.instance; | ||
if (parentInstance) { | ||
var self = this; | ||
this.__getChildContext = parentInstance.getChildContext; | ||
parentInstance.getChildContext = function () { | ||
var context = self.__getChildContext.call(this); | ||
return _extends({}, context, { parent: self }); | ||
}; | ||
} | ||
this.__parentInstance = parentInstance; | ||
}; | ||
IntactReact.prototype.__popGetChildContext = function __popGetChildContext() { | ||
if (this.__parentInstance) { | ||
this.__parentInstance.getChildContext = this.__getChildContext; | ||
} | ||
}; | ||
IntactReact.prototype.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
@@ -575,3 +634,3 @@ var oldTriggerFlag = this._shouldTrigger; | ||
this.mountedQueue.push(function () { | ||
_this2.mount(); | ||
_this3.mount(); | ||
}); | ||
@@ -616,11 +675,13 @@ | ||
this._shouldTrigger = false; | ||
if (!mountedQueue || mountedQueue.done) { | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
// get from parent | ||
var tmp = void 0; | ||
if ((tmp = this.context) && (tmp = tmp.parent) && (tmp = tmp.mountedQueue)) { | ||
if (!tmp.done) { | ||
this.mountedQueue = tmp; | ||
return; | ||
} | ||
} | ||
this._shouldTrigger = true; | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
this._initMountedQueue(); | ||
} | ||
mountedQueue = this.mountedQueue; | ||
pushStack(); | ||
} else { | ||
this.mountedQueue = mountedQueue; | ||
this._initMountedQueue(); | ||
} | ||
@@ -630,14 +691,17 @@ }; | ||
IntactReact.prototype.__triggerMountedQueue = function __triggerMountedQueue() { | ||
var _this3 = this; | ||
var _this4 = this; | ||
if (this._shouldTrigger) { | ||
FakePromise.all(promises).then(function () { | ||
_this3._triggerMountedQueue(); | ||
FakePromise.all(this.promises).then(function () { | ||
_this4._triggerMountedQueue(); | ||
}); | ||
mountedQueue = null; | ||
this._shouldTrigger = false; | ||
popStack(); | ||
} | ||
}; | ||
IntactReact.prototype.__pushActiveInstance = function __pushActiveInstance() { | ||
var o = this._activeReactInstance; | ||
this._activeReactInstance = activeIntactReactInstance; | ||
}; | ||
createClass(IntactReact, [{ | ||
@@ -662,6 +726,8 @@ key: 'isMounted', | ||
_context: noop, | ||
parent: noop | ||
parent: noop, | ||
promises: noop | ||
}; | ||
IntactReact.childContextTypes = { | ||
parent: noop | ||
parent: noop, | ||
promises: noop | ||
}; | ||
@@ -668,0 +734,0 @@ |
@@ -1,1 +0,1 @@ | ||
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?module.exports=e(require("react"),require("intact/dist"),require("react-dom")):typeof define==="function"&&define.amd?define(["react","intact/dist","react-dom"],e):t.Intact=e(t.React,t.Intact,t.ReactDOM)})(this,function(t,e,r){"use strict";t=t&&t.hasOwnProperty("default")?t["default"]:t;e=e&&e.hasOwnProperty("default")?e["default"]:e;r=r&&r.hasOwnProperty("default")?r["default"]:r;var n=function(t,e){if(!(t instanceof e)){throw new TypeError("Cannot call a class as a function")}};var i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||false;n.configurable=true;if("value"in n)n.writable=true;Object.defineProperty(t,n.key,n)}}return function(e,r,n){if(r)t(e.prototype,r);if(n)t(e,n);return e}}();var o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r){if(Object.prototype.hasOwnProperty.call(r,n)){t[n]=r[n]}}}return t};var a=function(t,e){if(typeof e!=="function"&&e!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof e)}t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:false,writable:true,configurable:true}});if(e)Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e};var u=function(t,e){if(!t){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e&&(typeof e==="object"||typeof e==="function")?e:t};var s=function(){function t(e){var r=this;n(this,t);this.resolved=false;this.callback=undefined;e.call(this,function(){return r.resolve()})}t.prototype.resolve=function t(){this.resolved=true;this.callback&&this.callback()};t.prototype.then=function t(e){this.callback=e;if(this.resolved){this.callback()}};return t}();s.all=function(t){var e=t.length;var r=0;var n=void 0;t.forEach(function(t){t.then(function(){r++;if(e===r){n&&n()}})});return{then:function t(r){n=r;if(!e){n()}}}};var c=[];var p=[];function l(){p.push(c);c=[]}function h(){c=p.pop()}var f=function(){function t(){n(this,t)}t.prototype.init=function t(e,r){this.destroyed=true;this.placeholder=document.createComment(" react-mount-point-unstable ");this._render(r);return this.placeholder};t.prototype.update=function t(e,r){this._render(r);return this.placeholder};t.prototype.destroy=function t(){var e=this.placeholder;e._unmount=function(){r.render(null,e,function(){e.parentNode.removeChild(e)})}};t.prototype._render=function t(e){var n=this;var i=this._addProps(e);var o=e.props.parentRef.instance;var a=new s(function(t){if(o&&o._reactInternalFiber!==undefined){r.unstable_renderSubtreeIntoContainer(o,i,n.placeholder,t)}else{r.render(i,n.placeholder,t)}});c.push(a)};t.prototype._addProps=function t(e){this.vdt={vNode:e};var r=e.props;var n=void 0;var i=void 0;for(var a in r){if(a==="reactVNode"||a==="parentRef")continue;if(!n){n=o({},r.reactVNode);i=n.props=o({},n.props)}var u=r[a];if(a.substr(0,3)==="ev-"){i[d[a]]=u}else{i[a]=u}}return n||r.reactVNode};return t}();var d={"ev-click":"onClick","ev-mouseenter":"onMouseEnter","ev-mouseleave":"onMouseLeave"};var v=t.createElement;function y(t,e,r){var n=t.$$cid==="IntactReact";var i=t.propTypes;if(n&&i){t.propTypes=undefined}var o=v.apply(this,arguments);if(n&&i){t.propTypes=i}return o}t.createElement=y;var _=e.Vdt.miss;var g=_.h;var m=_.VNode;var b=e.utils;var N=b.isFunction;var w=b.isArray;var R=b.isStringOrNumber;var T=b.set;var O=b.get;function Q(t,e){if(t==null)return t;if(R(t))return t;if(t instanceof m){if(t.tag===f){t.props.parentRef=e}return t}if(t.type&&t.type.$$cid==="IntactReact"){return g(t.type,M(t.props,{_context:t._owner&&t._owner.stateNode},e,t.key),null,null,t.key,t.ref)}return g(f,{reactVNode:t,parentRef:e})}function x(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(w(t)){return t.map(function(t){return Q(t,e)})}return Q(t,e)}function M(t,e,r,n){if(!t)return;var i={};var o=i._blocks={};var a=void 0;for(var u in t){if(u==="children"){i.children=x(t.children,r)}else if(a=E(u)){i[a]=t[u]}else if(u.substring(0,2)==="b-"){o[u.substring(2)]=k(t[u])}else{i[u]=t[u]}}i._context=C(e);if(n!=null){i.key=n}return i}function C(t){var e=t._context;return{data:{get:function t(r){if(r!=null){return O(e.state,r)}else{return e.state}},set:function t(r,n){var i=o({},e.state);T(i,r,n);e.setState(i)}}}}function k(t){if(N(t)){return function(e){for(var r=arguments.length,n=Array(r>1?r-1:0),i=1;i<r;i++){n[i-1]=arguments[i]}return x(t.apply(this,n),{instance:this.data})}}else{return function(){return x(t,{instance:this.data})}}}function E(t){var e=t[0],r=t[1],n=t[2];var i=void 0;if(e==="o"&&r==="n"){if(n==="$"){return"ev-$"+t.substring(3).replace(/\-/g,":")}else if((i=n.charCodeAt(0))&&i>=65&&i<=90){return"ev-"+t.substring(2).toLowerCase()}}}var V=e.utils;var j=V.isStringOrNumber;var A=V.isArray;function P(t){function e(e,r){if(r){var n=t(M(e,r,{}),true);if(A(n)){return n.map(function(t){return $(t)})}return $(n)}else{return t(e)}}return e}function $(t){if(j(t)){return t}else if(t){return y(t.tag,t.props,t.props.children||t.children)}}var I=e.utils;var S=I.noop;var q=I.isArray;var D=I.isObject;var F=e.Vdt.miss.h;var L=void 0;var U=function(e){a(r,e);function r(t,i){n(this,r);if(i){var o={};var a=M(t,i,o);var s=u(this,e.call(this,a));o.instance=s;s.vNode=F(s.constructor,a);s.vNode.children=s;s._props=s.props;delete s.props;s._isReact=true}else{var s=u(this,e.call(this,t))}return u(s)}r.prototype.getChildContext=function t(){return{parent:this}};r.prototype.get=function t(){for(var r=arguments.length,n=Array(r),i=0;i<r;i++){n[i]=arguments[i]}if(this._isReact){var o;var a=this.props;this.props=this._props;var u=(o=e.prototype.get).call.apply(o,[this].concat(n));this.props=a;return u}else{var s;return(s=e.prototype.get).call.apply(s,[this].concat(n))}};r.prototype.set=function t(){for(var r=arguments.length,n=Array(r),i=0;i<r;i++){n[i]=arguments[i]}if(this._isReact){var o;var a=this.props;this.props=this._props;var u=(o=e.prototype.set).call.apply(o,[this].concat(n));this.props=a;return u}else{var s;return(s=e.prototype.set).call.apply(s,[this].concat(n))}};r.prototype.init=function t(){var r,n;for(var i=arguments.length,o=Array(i),a=0;a<i;a++){o[a]=arguments[a]}if(!this._isReact)return(r=e.prototype.init).call.apply(r,[this].concat(o));L=this.mountedQueue;return(n=e.prototype.init).call.apply(n,[this].concat(o))};r.prototype.update=function t(){var r,n;for(var i=arguments.length,o=Array(i),a=0;a<i;a++){o[a]=arguments[a]}if(!this._isReact)return(r=e.prototype.update).call.apply(r,[this].concat(o));var u=this._shouldTrigger;this.__initMountedQueue();var s=(n=e.prototype.update).call.apply(n,[this].concat(o));this.__triggerMountedQueue();this._shouldTrigger=u;return s};r.prototype.componentDidMount=function t(){var e=this;var r=this._shouldTrigger;this.__initMountedQueue();this.inited=true;this.parentVNode=this.vNode.parentVNode=this.context.parent&&this.context.parent.vNode;var n=this.init(null,this.vNode);var i=this._placeholder.parentElement;i.replaceChild(n,this._placeholder);this._placeholder._realElement=n;if(!i._hasRewrite){var o=i.removeChild;i.removeChild=function(t){o.call(this,t._realElement||t)};i._hasRewrite=true}this.mountedQueue.push(function(){e.mount()});this.__triggerMountedQueue();this._shouldTrigger=r};r.prototype.componentWillUnmount=function t(){this.destroy()};r.prototype.componentDidUpdate=function t(){var e=this._shouldTrigger;this.__initMountedQueue();var r=F(this.constructor,M(this.props,this.context,{instance:this}));var n=this.vNode;r.children=this;this.vNode=r;this.parentVNode=r.parentVNode=this.context.parent&&this.context.parent.vNode;this.update(n,r);this.__triggerMountedQueue();this._shouldTrigger=e};r.prototype.__ref=function t(e){this._placeholder=e};r.prototype.render=function e(){return t.createElement("i",{ref:this.__ref})};r.prototype.__initMountedQueue=function t(){this._shouldTrigger=false;if(!L||L.done){this._shouldTrigger=true;if(!this.mountedQueue||this.mountedQueue.done){this._initMountedQueue()}L=this.mountedQueue;l()}else{this.mountedQueue=L}};r.prototype.__triggerMountedQueue=function t(){var e=this;if(this._shouldTrigger){s.all(c).then(function(){e._triggerMountedQueue()});L=null;this._shouldTrigger=false;h()}};i(r,[{key:"isMounted",get:function t(){return this.mounted}}]);return r}(e);U.functionalWrapper=P;U.normalize=x;U.$$cid="IntactReact";U.prototype.isReactComponent={};U.contextTypes={_context:S,parent:S};U.childContextTypes={parent:S};return U}); | ||
(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?module.exports=e(require("react"),require("intact/dist"),require("react-dom")):typeof define==="function"&&define.amd?define(["react","intact/dist","react-dom"],e):t.Intact=e(t.React,t.Intact,t.ReactDOM)})(this,function(t,e,r){"use strict";t=t&&t.hasOwnProperty("default")?t["default"]:t;e=e&&e.hasOwnProperty("default")?e["default"]:e;r=r&&r.hasOwnProperty("default")?r["default"]:r;var n=function(t,e){if(!(t instanceof e)){throw new TypeError("Cannot call a class as a function")}};var i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||false;n.configurable=true;if("value"in n)n.writable=true;Object.defineProperty(t,n.key,n)}}return function(e,r,n){if(r)t(e.prototype,r);if(n)t(e,n);return e}}();var o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r){if(Object.prototype.hasOwnProperty.call(r,n)){t[n]=r[n]}}}return t};var a=function(t,e){if(typeof e!=="function"&&e!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof e)}t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:false,writable:true,configurable:true}});if(e)Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e};var s=function(t,e){if(!t){throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}return e&&(typeof e==="object"||typeof e==="function")?e:t};var u=function(){function t(e){var r=this;n(this,t);this.resolved=false;this.callbacks=[];e.call(this,function(){return r.resolve()})}t.prototype.resolve=function t(){this.resolved=true;var e=void 0;while(e=this.callbacks.shift()){e()}};t.prototype.then=function t(e){this.callbacks.push(e);if(this.resolved){this.resolve()}};return t}();u.all=function(t){var e=0;var r=void 0;var n=false;var i=false;t.forEach(function(t){return t.then(s)});if(t._hasRewrite){console.error("promises has not been done")}var o=t.push;t.push=function(e){e.then(s);o.call(t,e)};t._hasRewrite=true;function a(){t.length=0;t.push=o;t._hasRewrite=false;r()}function s(){e++;if(t.length===e){n=true;if(i){return console.error("promise has done")}if(r){i=true;a()}}}return{then:function e(i){r=i;if(!t.length||n){a()}}}};var p=function(){function t(){n(this,t)}t.prototype.init=function t(e,r){this.destroyed=true;this.placeholder=document.createComment(" react-mount-point-unstable ");this._render(r);return this.placeholder};t.prototype.update=function t(e,r){this._render(r);return this.placeholder};t.prototype.destroy=function t(){var e=this.placeholder;e._unmount=function(){r.render(null,e,function(){e.parentNode.removeChild(e)})}};t.prototype._render=function t(e){var n=this;var i=this._addProps(e);var o=e.props.parentRef.instance;if(o){if(!o._reactInternalFiber){o=o.get("parentRef").instance}}else{var a=e.parentVNode;while(a){var s=a.children;if(s&&s._reactInternalFiber!==undefined){o=s;break}a=a.parentVNode}}var p=new u(function(t){if(o&&o._reactInternalFiber!==undefined){r.unstable_renderSubtreeIntoContainer(o,i,n.placeholder,t)}else{r.render(i,n.placeholder,t)}});o.promises.push(p)};t.prototype._addProps=function t(e){this.vdt={vNode:e};var r=e.props;var n=void 0;var i=void 0;for(var a in r){if(a==="reactVNode"||a==="parentRef")continue;if(!n){n=o({},r.reactVNode);i=n.props=o({},n.props)}var s=r[a];if(a.substr(0,3)==="ev-"){i[c[a]]=s}else{i[a]=s}}return n||r.reactVNode};return t}();var c={"ev-click":"onClick","ev-mouseenter":"onMouseEnter","ev-mouseleave":"onMouseLeave"};var h=t.createElement;function l(t,e,r){var n=t.$$cid==="IntactReact";var i=t.propTypes;if(n&&i){t.propTypes=undefined}var o=h.apply(this,arguments);if(n&&i){t.propTypes=i}return o}t.createElement=l;var f=e.Vdt.miss;var d=f.h;var v=f.VNode;var _=e.utils;var y=_.isFunction;var g=_.isArray;var m=_.isStringOrNumber;var b=_.set;var C=_.get;function x(t,e){if(t==null)return t;if(m(t))return t;if(t instanceof v){if(t.tag===p){t.props.parentRef=e}return t}if(t.type&&t.type.$$cid==="IntactReact"){return d(t.type,N(o({},t.props,{parentRef:e}),{_context:t._owner&&t._owner.stateNode},e,t.key),null,null,t.key,t.ref)}return d(p,{reactVNode:t,parentRef:e})}function R(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(g(t)){return t.map(function(t){return x(t,e)})}return x(t,e)}function N(t,e,r,n){if(!t)return;var i={};var o=i._blocks={};var a=void 0;for(var s in t){if(s==="children"){i.children=R(t.children,r)}else if(a=Q(s)){i[a]=t[s]}else if(s.substring(0,2)==="b-"){o[s.substring(2)]=I(t[s])}else{i[s]=t[s]}}i._context=w(e);if(n!=null){i.key=n}return i}function w(t){var e=t._context;return{data:{get:function t(r){if(r!=null){return C(e.state,r)}else{return e.state}},set:function t(r,n){var i=o({},e.state);b(i,r,n);e.setState(i)}}}}function I(t){if(y(t)){return function(e){for(var r=arguments.length,n=Array(r>1?r-1:0),i=1;i<r;i++){n[i-1]=arguments[i]}return R(t.apply(this,n),{instance:this.data})}}else{return function(){return R(t,{instance:this.data})}}}function Q(t){var e=t[0],r=t[1],n=t[2];var i=void 0;if(e==="o"&&r==="n"){if(n==="$"){return"ev-$"+t.substring(3).replace(/\-/g,":")}else if((i=n.charCodeAt(0))&&i>=65&&i<=90){return"ev-"+t.substring(2).toLowerCase()}}}var T=e.utils;var O=T.isStringOrNumber;var M=T.isArray;function V(t){function e(e,r){if(r){var n=t(N(e,r,{}),true);if(M(n)){return n.map(function(t){return k(t)})}return k(n)}else{return t(e)}}return e}function k(t){if(O(t)){return t}else if(t){return l(t.tag,t.props,t.props.children||t.children)}}var E=e.utils;var j=E.noop;var P=E.isArray;var A=E.isObject;var $=e.Vdt.miss.h;var G=function(e){a(r,e);function r(t,i){n(this,r);if(i){var o={};var a=N(t,i,o);var u=s(this,e.call(this,a));o.instance=u;u.promises=i.promises||[];u.mountedQueue=i.parent&&i.parent.mountedQueue;u.vNode=$(u.constructor,a);u.vNode.children=u;u._props=u.props;delete u.props;u._isReact=true}else{var u=s(this,e.call(this,t))}return s(u)}r.prototype.getChildContext=function t(){return{parent:this,promises:this.promises}};r.prototype.get=function t(){for(var r=arguments.length,n=Array(r),i=0;i<r;i++){n[i]=arguments[i]}if(this._isReact){var o;var a=this.props;this.props=this._props;var s=(o=e.prototype.get).call.apply(o,[this].concat(n));this.props=a;return s}else{var u;return(u=e.prototype.get).call.apply(u,[this].concat(n))}};r.prototype.set=function t(){for(var r=arguments.length,n=Array(r),i=0;i<r;i++){n[i]=arguments[i]}if(this._isReact){var o;var a=this.props;this.props=this._props;var s=(o=e.prototype.set).call.apply(o,[this].concat(n));this.props=a;return s}else{var u;return(u=e.prototype.set).call.apply(u,[this].concat(n))}};r.prototype.init=function t(r,n){this.__pushGetChildContext(n);var i=e.prototype.init.call(this,r,n);this.__popGetChildContext();return i};r.prototype.update=function t(r,n,i){var o=this;var t=function t(){o.__pushGetChildContext(n);var a=e.prototype.update.call(o,r,n,i);o.__popGetChildContext();return a};if(!this._isReact)return t();var a=this._shouldTrigger;this.__initMountedQueue();var s=t();this.__triggerMountedQueue();this._shouldTrigger=a;return s};r.prototype.__pushGetChildContext=function t(e){var r=e&&e.props.parentRef;var n=r&&r.instance;if(n){var i=this;this.__getChildContext=n.getChildContext;n.getChildContext=function(){var t=i.__getChildContext.call(this);return o({},t,{parent:i})}}this.__parentInstance=n};r.prototype.__popGetChildContext=function t(){if(this.__parentInstance){this.__parentInstance.getChildContext=this.__getChildContext}};r.prototype.componentDidMount=function t(){var e=this;var r=this._shouldTrigger;this.__initMountedQueue();this.inited=true;this.parentVNode=this.vNode.parentVNode=this.context.parent&&this.context.parent.vNode;var n=this.init(null,this.vNode);var i=this._placeholder.parentElement;i.replaceChild(n,this._placeholder);this._placeholder._realElement=n;if(!i._hasRewrite){var o=i.removeChild;i.removeChild=function(t){o.call(this,t._realElement||t)};i._hasRewrite=true}this.mountedQueue.push(function(){e.mount()});this.__triggerMountedQueue();this._shouldTrigger=r};r.prototype.componentWillUnmount=function t(){this.destroy()};r.prototype.componentDidUpdate=function t(){var e=this._shouldTrigger;this.__initMountedQueue();var r=$(this.constructor,N(this.props,this.context,{instance:this}));var n=this.vNode;r.children=this;this.vNode=r;this.parentVNode=r.parentVNode=this.context.parent&&this.context.parent.vNode;this.update(n,r);this.__triggerMountedQueue();this._shouldTrigger=e};r.prototype.__ref=function t(e){this._placeholder=e};r.prototype.render=function e(){return t.createElement("i",{ref:this.__ref})};r.prototype.__initMountedQueue=function t(){this._shouldTrigger=false;if(!this.mountedQueue||this.mountedQueue.done){var e=void 0;if((e=this.context)&&(e=e.parent)&&(e=e.mountedQueue)){if(!e.done){this.mountedQueue=e;return}}this._shouldTrigger=true;this._initMountedQueue()}};r.prototype.__triggerMountedQueue=function t(){var e=this;if(this._shouldTrigger){u.all(this.promises).then(function(){e._triggerMountedQueue()});this._shouldTrigger=false}};r.prototype.__pushActiveInstance=function t(){var e=this._activeReactInstance;this._activeReactInstance=activeIntactReactInstance};i(r,[{key:"isMounted",get:function t(){return this.mounted}}]);return r}(e);G.functionalWrapper=V;G.normalize=R;G.$$cid="IntactReact";G.prototype.isReactComponent={};G.contextTypes={_context:j,parent:j,promises:j};G.childContextTypes={parent:j,promises:j};return G}); |
{ | ||
"name": "intact-react", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "A compatibility layer for running intact component in react v16", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
// make sure all mount/update lifecycle methods of children have completed | ||
export default class FakePromise { | ||
static all = function(promises) { | ||
let count = promises.length; | ||
let resolvedCount = 0; | ||
let callback; | ||
let resolved = false; | ||
let done = false; | ||
promises.forEach(p => { | ||
p.then(() => { | ||
resolvedCount++; | ||
if (count === resolvedCount) { | ||
callback && callback(); | ||
promises.forEach(p => p.then(then)); | ||
if (promises._hasRewrite) { | ||
console.error('promises has not been done') | ||
} | ||
const push = promises.push; | ||
promises.push = function(p) { | ||
p.then(then); | ||
push.call(promises, p); | ||
}; | ||
promises._hasRewrite = true; | ||
function _cb() { | ||
// clear array | ||
promises.length = 0; | ||
promises.push = push; | ||
promises._hasRewrite = false; | ||
callback(); | ||
} | ||
function then() { | ||
resolvedCount++; | ||
if (promises.length === resolvedCount) { | ||
resolved = true; | ||
if (done) { | ||
return console.error('promise has done'); | ||
} | ||
}); | ||
}); | ||
if (callback) { | ||
done = true; | ||
_cb(); | ||
} | ||
} | ||
} | ||
return { | ||
then(cb) { | ||
callback = cb; | ||
if (!count) { | ||
callback(); | ||
if (!promises.length || resolved) { | ||
_cb(); | ||
} | ||
@@ -29,3 +56,3 @@ } | ||
this.resolved = false; | ||
this.callback = undefined; | ||
this.callbacks = []; | ||
callback.call(this, () => this.resolve()); | ||
@@ -36,21 +63,14 @@ } | ||
this.resolved = true; | ||
this.callback && this.callback(); | ||
let cb; | ||
while (cb = this.callbacks.shift()) { | ||
cb(); | ||
} | ||
} | ||
then(cb) { | ||
this.callback = cb; | ||
this.callbacks.push(cb); | ||
if (this.resolved) { | ||
this.callback(); | ||
this.resolve(); | ||
} | ||
} | ||
} | ||
export let promises = []; | ||
const stacks = []; | ||
export function pushStack() { | ||
stacks.push(promises); | ||
promises = []; | ||
} | ||
export function popStack() { | ||
promises = stacks.pop(); | ||
} |
@@ -6,3 +6,3 @@ import React from 'react'; | ||
import functionalWrapper from './functionalWrapper'; | ||
import FakePromise, {promises, pushStack, popStack} from './FakePromise'; | ||
import FakePromise from './FakePromise'; | ||
@@ -12,4 +12,2 @@ const {noop, isArray, isObject} = Intact.utils; | ||
let mountedQueue; | ||
class IntactReact extends Intact { | ||
@@ -30,2 +28,5 @@ static functionalWrapper = functionalWrapper; | ||
this.promises = context.promises || []; | ||
this.mountedQueue = context.parent && context.parent.mountedQueue; | ||
// fake the vNode | ||
@@ -48,2 +49,3 @@ this.vNode = h(this.constructor, normalizedProps); | ||
parent: this, | ||
promises: this.promises, | ||
}; | ||
@@ -76,16 +78,23 @@ } | ||
init(...args) { | ||
if (!this._isReact) return super.init(...args); | ||
mountedQueue = this.mountedQueue; | ||
return super.init(...args); | ||
init(lastVNode, nextVNode) { | ||
this.__pushGetChildContext(nextVNode); | ||
const element = super.init(lastVNode, nextVNode); | ||
this.__popGetChildContext(); | ||
return element; | ||
} | ||
update(...args) { | ||
if (!this._isReact) return super.update(...args); | ||
update(lastVNode, nextVNode, fromPending) { | ||
const update = () => { | ||
this.__pushGetChildContext(nextVNode); | ||
const element = super.update(lastVNode, nextVNode, fromPending); | ||
this.__popGetChildContext(); | ||
return element; | ||
} | ||
if (!this._isReact) return update(); | ||
const oldTriggerFlag = this._shouldTrigger; | ||
this.__initMountedQueue(); | ||
const element = super.update(...args); | ||
const element = update(); | ||
@@ -98,2 +107,23 @@ this.__triggerMountedQueue(); | ||
__pushGetChildContext(nextVNode) { | ||
const parentRef = nextVNode && nextVNode.props.parentRef; | ||
const parentInstance = parentRef && parentRef.instance; | ||
if (parentInstance) { | ||
const self = this; | ||
this.__getChildContext = parentInstance.getChildContext; | ||
parentInstance.getChildContext = function() { | ||
const context = self.__getChildContext.call(this); | ||
return {...context, parent: self}; | ||
}; | ||
} | ||
this.__parentInstance = parentInstance; | ||
} | ||
__popGetChildContext() { | ||
if (this.__parentInstance) { | ||
this.__parentInstance.getChildContext = this.__getChildContext; | ||
} | ||
} | ||
componentDidMount() { | ||
@@ -175,11 +205,13 @@ const oldTriggerFlag = this._shouldTrigger; | ||
this._shouldTrigger = false; | ||
if (!mountedQueue || mountedQueue.done) { | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
// get from parent | ||
let tmp; | ||
if ((tmp = this.context) && (tmp = tmp.parent) && (tmp = tmp.mountedQueue)) { | ||
if (!tmp.done) { | ||
this.mountedQueue = tmp; | ||
return; | ||
} | ||
} | ||
this._shouldTrigger = true; | ||
if (!this.mountedQueue || this.mountedQueue.done) { | ||
this._initMountedQueue(); | ||
} | ||
mountedQueue = this.mountedQueue; | ||
pushStack(); | ||
} else { | ||
this.mountedQueue = mountedQueue; | ||
this._initMountedQueue(); | ||
} | ||
@@ -190,10 +222,14 @@ } | ||
if (this._shouldTrigger) { | ||
FakePromise.all(promises).then(() => { | ||
FakePromise.all(this.promises).then(() => { | ||
this._triggerMountedQueue(); | ||
}); | ||
mountedQueue = null; | ||
this._shouldTrigger = false; | ||
popStack(); | ||
} | ||
} | ||
__pushActiveInstance() { | ||
const o = this._activeReactInstance; | ||
this._activeReactInstance = activeIntactReactInstance; | ||
} | ||
} | ||
@@ -207,5 +243,7 @@ | ||
parent: noop, | ||
promises: noop, | ||
}; | ||
IntactReact.childContextTypes = { | ||
parent: noop | ||
parent: noop, | ||
promises: noop, | ||
}; | ||
@@ -212,0 +250,0 @@ |
@@ -25,3 +25,3 @@ import Intact from 'intact/dist'; | ||
normalizeProps( | ||
vNode.props, | ||
{...vNode.props, parentRef}, | ||
{_context: vNode._owner && vNode._owner.stateNode}, | ||
@@ -28,0 +28,0 @@ parentRef, |
import ReactDOM from 'react-dom'; | ||
import FakePromise, {promises} from './FakePromise'; | ||
import FakePromise from './FakePromise'; | ||
@@ -35,3 +35,21 @@ // wrap the react element to render it by react self | ||
const parentComponent = nextVNode.props.parentRef.instance; | ||
let parentComponent = nextVNode.props.parentRef.instance; | ||
if (parentComponent) { | ||
if (!parentComponent._reactInternalFiber) { | ||
// is a firsthand intact component, get its parent instance | ||
parentComponent = parentComponent.get('parentRef').instance; | ||
} | ||
} else { | ||
// maybe the property which value is vNodes | ||
// find the closest IntactReact instance | ||
let parentVNode = nextVNode.parentVNode; | ||
while (parentVNode) { | ||
const children = parentVNode.children; | ||
if (children && children._reactInternalFiber !== undefined) { | ||
parentComponent = children; | ||
break; | ||
} | ||
parentVNode = parentVNode.parentVNode; | ||
} | ||
} | ||
const promise = new FakePromise(resolve => { | ||
@@ -49,3 +67,3 @@ if (parentComponent && parentComponent._reactInternalFiber !== undefined) { | ||
}); | ||
promises.push(promise); | ||
parentComponent.promises.push(promise); | ||
} | ||
@@ -52,0 +70,0 @@ |
import Intact from '../index'; | ||
import React, {Component} from 'react' | ||
import ReactDOM from 'react-dom' | ||
import {promises} from '../src/FakePromise'; | ||
@@ -28,3 +27,6 @@ describe('Unit test', function() { | ||
const SimpleIntactComponent = createIntactComponent('<div>Intact Component</div>'); | ||
const ChildrenIntactComponent = createIntactComponent(`<div>{self.get('children')}</div>`); | ||
const ChildrenIntactComponent = createIntactComponent(`<div>{self.get('children')}</div>`,{ | ||
displayName: 'ChildrenIntactComponent', | ||
}); | ||
ChildrenIntactComponent.displayName = 'ChildrenIntactComponent'; | ||
const PropsIntactComponent = createIntactComponent(`<div>a: {self.get('a')} b: {self.get('b')}</div>`); | ||
@@ -155,2 +157,13 @@ class SimpleReactComponent extends Component { | ||
}); | ||
it('normalize the property which value is vNodes', () => { | ||
const C = createIntactComponent(`<div>{normalize(self.get('test'))}</div>`, { | ||
_init() { | ||
this.normalize = Intact.normalize; | ||
} | ||
}); | ||
render(<C test={<div>test</div>} />); | ||
expect(container.innerHTML).to.eql('<div><div>test</div></div>'); | ||
}); | ||
}); | ||
@@ -340,4 +353,2 @@ | ||
instance.i.set('v', 2); | ||
// should empty the promise array | ||
expect(promises).to.eql([]); | ||
}); | ||
@@ -553,3 +564,3 @@ }); | ||
describe('vNode', () => { | ||
it('should get parentVNode', () => { | ||
it('should get parentVNode of nested intact component', () => { | ||
const C = createIntactComponent(`<div>{self.get('children')}</div>`, { | ||
@@ -559,2 +570,3 @@ displayName: 'C', | ||
expect(this.parentVNode === undefined).to.be.true; | ||
console.log(this.element.innerHTML); | ||
} | ||
@@ -582,13 +594,51 @@ }); | ||
expect(this.parentVNode.parentVNode.children).be.an.instanceof(C); | ||
} | ||
}, | ||
displayName: 'F', | ||
}); | ||
const G = createIntactComponent('<b>g</b>', { | ||
_mount() { | ||
expect(this.parentVNode.parentVNode.tag === ChildrenIntactComponent).to.be.true; | ||
}, | ||
displayName: 'G', | ||
}); | ||
const instance = renderApp(function() { | ||
return <C> | ||
<p><E><b><D /></b></E></p> | ||
<F /> | ||
</C> | ||
return <div> | ||
<C> | ||
<p><E><b><D /></b></E></p> | ||
<F /> | ||
<ChildrenIntactComponent><G /></ChildrenIntactComponent> | ||
</C> | ||
<ChildrenIntactComponent><div>aaa</div></ChildrenIntactComponent> | ||
</div> | ||
}); | ||
}); | ||
it('should get parentVNode which return by functional component', () => { | ||
const h = Intact.Vdt.miss.h; | ||
const C = Intact.functionalWrapper((props) => { | ||
return h(D, props); | ||
}); | ||
const D = createIntactComponent(`<div>test</div>`, { | ||
displayName: 'D', | ||
_mount() { | ||
expect(this.parentVNode.tag === E).to.be.true; | ||
} | ||
}); | ||
D.displayName = 'D'; | ||
const E = createIntactComponent(`<div>{self.get('children')}</div>`, { | ||
displayName: 'E', | ||
}); | ||
E.displayName = 'E'; | ||
const instance = renderApp(function() { | ||
return ( | ||
<ChildrenIntactComponent> | ||
<E> | ||
<C /> | ||
</E> | ||
</ChildrenIntactComponent> | ||
) | ||
}); | ||
}); | ||
it('should get parentVNode in template & update', () => { | ||
@@ -595,0 +645,0 @@ const mount = sinon.spy(); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
106849
2488
0