intact-react
Advanced tools
Comparing version 1.1.19 to 1.1.20
@@ -372,5 +372,9 @@ 'use strict'; | ||
} | ||
// if there are providers, pass it to subtree | ||
var providers = parentComponent.__providers; | ||
providers.forEach(function (value, provider) { | ||
vNode = React.createElement(provider, { value: value }, vNode); | ||
}); | ||
var promise = new FakePromise(function (resolve) { | ||
// the parentComponent should always be valid | ||
// if (parentComponent && parentComponent._reactInternalFiber !== undefined) { | ||
ReactDOM.unstable_renderSubtreeIntoContainer(parentComponent, vNode, placeholder, | ||
@@ -381,3 +385,3 @@ // this.parentDom, | ||
// the Wrapper node is returned by parent component directly | ||
// in this case we must fix the element property of parent component | ||
// in this case we must fix the element property of parent component. | ||
// 3 is textNode | ||
@@ -388,5 +392,2 @@ var dom = this && this.nodeType === 3 ? this : ReactDOM.findDOMNode(this); | ||
}); | ||
// } else { | ||
// ReactDOM.render(vNode, this.placeholder, resolve); | ||
// } | ||
}); | ||
@@ -837,2 +838,12 @@ parentComponent.__promises.push(promise); | ||
IntactReact.prototype.render = function render() { | ||
// save all context.Provider | ||
this.__providers = new Map(); | ||
var returnFiber = this._reactInternalFiber; | ||
while (returnFiber = returnFiber.return) { | ||
// is ContextProvider | ||
if (returnFiber.tag === 10) { | ||
var type = returnFiber.type; | ||
this.__providers.set(type, type._context._currentValue); | ||
} | ||
} | ||
return React.createElement('i', { | ||
@@ -839,0 +850,0 @@ ref: this.__ref |
@@ -374,5 +374,9 @@ (function (global, factory) { | ||
} | ||
// if there are providers, pass it to subtree | ||
var providers = parentComponent.__providers; | ||
providers.forEach(function (value, provider) { | ||
vNode = React.createElement(provider, { value: value }, vNode); | ||
}); | ||
var promise = new FakePromise(function (resolve) { | ||
// the parentComponent should always be valid | ||
// if (parentComponent && parentComponent._reactInternalFiber !== undefined) { | ||
ReactDOM.unstable_renderSubtreeIntoContainer(parentComponent, vNode, placeholder, | ||
@@ -383,3 +387,3 @@ // this.parentDom, | ||
// the Wrapper node is returned by parent component directly | ||
// in this case we must fix the element property of parent component | ||
// in this case we must fix the element property of parent component. | ||
// 3 is textNode | ||
@@ -390,5 +394,2 @@ var dom = this && this.nodeType === 3 ? this : ReactDOM.findDOMNode(this); | ||
}); | ||
// } else { | ||
// ReactDOM.render(vNode, this.placeholder, resolve); | ||
// } | ||
}); | ||
@@ -839,2 +840,12 @@ parentComponent.__promises.push(promise); | ||
IntactReact.prototype.render = function render() { | ||
// save all context.Provider | ||
this.__providers = new Map(); | ||
var returnFiber = this._reactInternalFiber; | ||
while (returnFiber = returnFiber.return) { | ||
// is ContextProvider | ||
if (returnFiber.tag === 10) { | ||
var type = returnFiber.type; | ||
this.__providers.set(type, type._context._currentValue); | ||
} | ||
} | ||
return React.createElement('i', { | ||
@@ -841,0 +852,0 @@ ref: this.__ref |
@@ -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=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol==="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};var i=function(t,e){if(!(t instanceof e)){throw new TypeError("Cannot call a class as a function")}};var o=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 a=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 s=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 p=function(){function t(e){var r=this;i(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}();p.all=function(t){var e=0;var r=t.callbacks||(t.callbacks=[]);var n=false;var i=false;t.forEach(function(t){if(t._hasRewrite)return;t._hasRewrite=true;t.then(s)});if(!t._hasRewrite){var o=t.push;t.push=function(e){e.then(s);o.call(t,e)};t.push.push=o;t._hasRewrite=true}function a(){t.length=0;t.push=t.push.push;t._hasRewrite=false;t.callbacks=[];var e=void 0;while(e=r.shift()){e()}}function s(){e++;if(t.length===e){n=true;if(i){return console.error("promise has done")}if(r.length){i=true;a()}}}return{then:function e(i){r.push(i);if(!t.length||n){a()}}}};var c=t.createElement;function l(t,e,r){var n=t.$$cid==="IntactReact";var i=t.propTypes;if(n&&i){t.propTypes=undefined}var o=c.apply(this,arguments);if(n&&i){t.propTypes=i}return o}t.createElement=l;var f=r.findDOMNode;r.findDOMNode=function(t){if(t instanceof H){return t.element}return f.call(r,t)};var h=e.Vdt.miss;var d=h.h;h.h=function t(e){if(e&&e.$$cid==="IntactFunction"){e=e.$$type}for(var r=arguments.length,n=Array(r>1?r-1:0),i=1;i<r;i++){n[i-1]=arguments[i]}return d.call.apply(d,[this,e].concat(n))};var v=e.utils;var _=v.isStringOrNumber;var y=v.isArray;var g=v.noop;function m(e){function r(t,r){if(r){var n=e(S(t,r,{instance:r.__parent}),true);if(y(n)){return n.map(function(t){return b(t)})}return b(n)}else{return e(t)}}r.contextTypes={_context:g,__parent:g};var n=t.forwardRef(function(t,e){if(e)t=a({},t,{forwardRef:e});return l(r,t)});n.$$cid="IntactFunction";n.$$type=r;return n}function b(t){if(_(t)){return t}else if(t){return l(t.tag,t.props,t.props.children||t.children)}}var C=/_ev[A-Z]/;var x=" react-mount-point-unstable ";var N=function(){function t(){i(this,t)}t.prototype.init=function t(e,r){this.destroyed=true;var n=this.placeholder=document.createComment(x);var i=this.parentDom;if(!i){var o=this.parentVNode;while(o){if(o.dom){i=o.dom;break}o=o.parentVNode}}if(i){i.appendChild(n)}this._render(r);return n};t.prototype.update=function t(e,r){this._render(r);return this.placeholder};t.prototype.destroy=function t(e,n,i){var o=this.placeholder;r.render(null,o,function(){var t=o.parentNode;Object.defineProperty(o,"parentNode",{value:t});t.removeChild(o)});o._unmount=g;if(o._realElement){o._realElement._unmount=g}};t.prototype._render=function t(e){var n=this._addProps(e);var i=this.placeholder;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 u=new p(function(t){r.unstable_renderSubtreeIntoContainer(o,n,i,function(){var e=this&&this.nodeType===3?this:r.findDOMNode(this);i._realElement=e;t()})});o.__promises.push(u)};t.prototype._addProps=function t(e){this.vdt={vNode:e};var r=e.props;var n=void 0;var i=void 0;for(var o in r){if(o==="reactVNode"||o==="_parentRef")continue;if(C.test(o))continue;if(!n){n=a({},r.reactVNode);i=n.props=a({},n.props)}var s=r[o];if(o.substr(0,3)==="ev-"){i[w[o]]=s}else{i[o]=s}}return n||r.reactVNode};return t}();var w={"ev-click":"onClick","ev-mouseenter":"onMouseEnter","ev-mouseleave":"onMouseLeave"};var R=e.Vdt.miss;var O=R.h;var k=R.VNode;var M=R.Types;var E=e.utils;var Q=E.isFunction;var T=E.isArray;var V=E.isStringOrNumber;var $=E.set;var j=E.get;function I(e,r){if(e==null)return e;if(V(e)){return new k(M.Text,null,null,e)}if(e instanceof k){if(Q(e.tag)){e.props._parentRef=r}return e}var n=void 0;if((n=e.type)&&(n=n.$$cid)&&(n==="IntactReact"||n==="IntactFunction")){return O(e.type,S(a({},e.props,{_parentRef:r}),{_context:e._owner&&e._owner.stateNode},r,e.key),null,null,e.key,F(e.ref))}if(e.type===t.Fragment){return P(e.props.children,r)}return O(N,{reactVNode:e,_parentRef:r},null,e.props.className)}function P(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(T(t)){var r=[];t.forEach(function(t){if(T(t)){r.push.apply(r,P(t,e))}else{r.push(I(t,e))}});return r}return I(t,e)}function S(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=P(t.children,r)}else if(a=D(s)){i[a]=t[s]}else if(s.substring(0,2)==="b-"){o[s.substring(2)]=A(t[s])}else if(s==="forwardRef"){i.ref=t[s]}else{i[s]=t[s]}}i._context=U(e);if(n!=null){i.key=n}return i}function F(t){return(typeof t==="undefined"?"undefined":n(t))==="object"&&t!==null?function(e){t.current=e}:t}function U(t){var e=t._context;return{data:{get:function t(r){if(r!=null){return j(e.state||{},r)}else{return e.state||{}}},set:function t(r,n){var i=a({},e.state);$(i,r,n);e.setState(i)}}}}function A(t){if(Q(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 P(t.apply(this,n),{instance:this.data})}}else{return function(){return P(t,{instance:this.data})}}}function D(t){var e=t[0],r=t[1],n=t[2];if(!n)return;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().replace(/\-/g,":")}}}var G=e.utils;var q=G.isObject;var B=G.extend;var L=e.Vdt.miss.h;var W=void 0;var z=void 0;var Z=[];var H=function(e){s(r,e);function r(t,n){i(this,r);if(n){var o={};var a=S(t,n,o);var s=u(this,e.call(this,a));o.instance=s;s.__promises=n.__promises||Z;s.mountedQueue=n.__parent&&n.__parent.mountedQueue;s.vNode=L(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))}s._triggerFlagStack=[];var p=void 0;Object.defineProperty(s,"element",{get:function t(){if(!this.__isUpdating&&p&&p.nodeType===8&&p.nodeValue===x){return p._realElement||p}return p},set:function t(e){p=e},configurable:true,enumerable:true});return u(s)}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){var i=this.__isUpdating;this.__isUpdating=true;this.refs=this.vdt.widgets||{};this.__pushGetChildContext(n);var o=e.prototype.init.call(this,r,n);this.__popGetChildContext();this.__isUpdating=i;return o};r.prototype.update=function t(r,n,i){var o=this;var t=function t(){var a=o.__isUpdating;o.__isUpdating=true;var s=!a&&!o.__getChildContext;if(s){o.__pushGetChildContext(n||o.vNode)}var u=e.prototype.update.call(o,r,n,i);if(s){o.__popGetChildContext()}o.__isUpdating=a;return u};if(!this._isReact)return t();this.__initMountedQueue();var a=t();this.__triggerMountedQueue();return a};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 a({},t,{__parent:i})}}this.__parentInstance=n};r.prototype.__popGetChildContext=function t(){if(this.__parentInstance){this.__parentInstance.getChildContext=this.__getChildContext;this.__getChildContext=null}};r.prototype.componentDidMount=function t(){var e=this;this.__initMountedQueue();this.inited=true;this.parentVNode=this.vNode.parentVNode=this.context.__parent&&this.context.__parent.vNode;var r=this.init(null,this.vNode);var n=this._placeholder;var i=n.parentElement;this.parentDom=i;r[W]=n[W];r[z]=n[z];Object.defineProperty(n,"parentNode",{value:i});i.replaceChild(r,n);n._realElement=r;if(!i._hasRewrite){var o=i.removeChild;i.removeChild=function(t){o.call(this,t._realElement||t)};var a=i.insertBefore;i.insertBefore=function(t,e){a.call(this,t,e._realElement||e)};i._hasRewrite=true}this.mountedQueue.push(function(){e.mount()});this.__triggerMountedQueue()};r.prototype.componentWillUnmount=function t(){this.destroy()};r.prototype.componentDidUpdate=function t(){this.__initMountedQueue();var e=L(this.constructor,S(this.props,this.context,{instance:this}));var r=this.vNode;e.children=this;this.vNode=e;this.parentVNode=e.parentVNode=this.context.__parent&&this.context.__parent.vNode;this.update(r,e);this.__triggerMountedQueue()};r.prototype.__ref=function t(e){this._placeholder=e;if(!W){var r=Object.keys(e);W=r[0];z=r[1]}};r.prototype.render=function e(){return t.createElement("i",{ref:this.__ref})};r.prototype.__initMountedQueue=function t(){this._triggerFlagStack.push(this._shouldTrigger);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){p.all(this.__promises).then(function(){Z=[];e._triggerMountedQueue()})}this._shouldTrigger=this._triggerFlagStack.pop()};o(r,[{key:"isMounted",get:function t(){return this.mounted}}]);return r}(e);H.functionalWrapper=m;H.normalize=P;H.$$cid="IntactReact";H.prototype.isReactComponent={};H.contextTypes={_context:g,__parent:g,__promises:g,router:g};H.childContextTypes={__parent:g,__promises:g};if(!Object.setPrototypeOf){B(H,e);if(!H.template){H.template=e.template}}return H}); | ||
(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=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol==="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};var i=function(t,e){if(!(t instanceof e)){throw new TypeError("Cannot call a class as a function")}};var o=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 a=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 s=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 p=function(){function t(e){var r=this;i(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}();p.all=function(t){var e=0;var r=t.callbacks||(t.callbacks=[]);var n=false;var i=false;t.forEach(function(t){if(t._hasRewrite)return;t._hasRewrite=true;t.then(s)});if(!t._hasRewrite){var o=t.push;t.push=function(e){e.then(s);o.call(t,e)};t.push.push=o;t._hasRewrite=true}function a(){t.length=0;t.push=t.push.push;t._hasRewrite=false;t.callbacks=[];var e=void 0;while(e=r.shift()){e()}}function s(){e++;if(t.length===e){n=true;if(i){return console.error("promise has done")}if(r.length){i=true;a()}}}return{then:function e(i){r.push(i);if(!t.length||n){a()}}}};var c=t.createElement;function l(t,e,r){var n=t.$$cid==="IntactReact";var i=t.propTypes;if(n&&i){t.propTypes=undefined}var o=c.apply(this,arguments);if(n&&i){t.propTypes=i}return o}t.createElement=l;var f=r.findDOMNode;r.findDOMNode=function(t){if(t instanceof H){return t.element}return f.call(r,t)};var h=e.Vdt.miss;var d=h.h;h.h=function t(e){if(e&&e.$$cid==="IntactFunction"){e=e.$$type}for(var r=arguments.length,n=Array(r>1?r-1:0),i=1;i<r;i++){n[i-1]=arguments[i]}return d.call.apply(d,[this,e].concat(n))};var _=e.utils;var v=_.isStringOrNumber;var y=_.isArray;var g=_.noop;function m(e){function r(t,r){if(r){var n=e(S(t,r,{instance:r.__parent}),true);if(y(n)){return n.map(function(t){return b(t)})}return b(n)}else{return e(t)}}r.contextTypes={_context:g,__parent:g};var n=t.forwardRef(function(t,e){if(e)t=a({},t,{forwardRef:e});return l(r,t)});n.$$cid="IntactFunction";n.$$type=r;return n}function b(t){if(v(t)){return t}else if(t){return l(t.tag,t.props,t.props.children||t.children)}}var C=/_ev[A-Z]/;var x=" react-mount-point-unstable ";var w=function(){function e(){i(this,e)}e.prototype.init=function t(e,r){this.destroyed=true;var n=this.placeholder=document.createComment(x);var i=this.parentDom;if(!i){var o=this.parentVNode;while(o){if(o.dom){i=o.dom;break}o=o.parentVNode}}if(i){i.appendChild(n)}this._render(r);return n};e.prototype.update=function t(e,r){this._render(r);return this.placeholder};e.prototype.destroy=function t(e,n,i){var o=this.placeholder;r.render(null,o,function(){var t=o.parentNode;Object.defineProperty(o,"parentNode",{value:t});t.removeChild(o)});o._unmount=g;if(o._realElement){o._realElement._unmount=g}};e.prototype._render=function e(n){var i=this._addProps(n);var o=this.placeholder;var a=n.props._parentRef.instance;if(a){if(!a._reactInternalFiber){a=a.get("_parentRef").instance}}else{var s=n.parentVNode;while(s){var u=s.children;if(u&&u._reactInternalFiber!==undefined){a=u;break}s=s.parentVNode}}var c=a.__providers;c.forEach(function(e,r){i=t.createElement(r,{value:e},i)});var l=new p(function(t){r.unstable_renderSubtreeIntoContainer(a,i,o,function(){var e=this&&this.nodeType===3?this:r.findDOMNode(this);o._realElement=e;t()})});a.__promises.push(l)};e.prototype._addProps=function t(e){this.vdt={vNode:e};var r=e.props;var n=void 0;var i=void 0;for(var o in r){if(o==="reactVNode"||o==="_parentRef")continue;if(C.test(o))continue;if(!n){n=a({},r.reactVNode);i=n.props=a({},n.props)}var s=r[o];if(o.substr(0,3)==="ev-"){i[N[o]]=s}else{i[o]=s}}return n||r.reactVNode};return e}();var N={"ev-click":"onClick","ev-mouseenter":"onMouseEnter","ev-mouseleave":"onMouseLeave"};var R=e.Vdt.miss;var O=R.h;var k=R.VNode;var E=R.Types;var M=e.utils;var V=M.isFunction;var Q=M.isArray;var T=M.isStringOrNumber;var $=M.set;var j=M.get;function I(e,r){if(e==null)return e;if(T(e)){return new k(E.Text,null,null,e)}if(e instanceof k){if(V(e.tag)){e.props._parentRef=r}return e}var n=void 0;if((n=e.type)&&(n=n.$$cid)&&(n==="IntactReact"||n==="IntactFunction")){return O(e.type,S(a({},e.props,{_parentRef:r}),{_context:e._owner&&e._owner.stateNode},r,e.key),null,null,e.key,F(e.ref))}if(e.type===t.Fragment){return P(e.props.children,r)}return O(w,{reactVNode:e,_parentRef:r},null,e.props.className)}function P(t){var e=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(Q(t)){var r=[];t.forEach(function(t){if(Q(t)){r.push.apply(r,P(t,e))}else{r.push(I(t,e))}});return r}return I(t,e)}function S(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=P(t.children,r)}else if(a=D(s)){i[a]=t[s]}else if(s.substring(0,2)==="b-"){o[s.substring(2)]=A(t[s])}else if(s==="forwardRef"){i.ref=t[s]}else{i[s]=t[s]}}i._context=U(e);if(n!=null){i.key=n}return i}function F(t){return(typeof t==="undefined"?"undefined":n(t))==="object"&&t!==null?function(e){t.current=e}:t}function U(t){var e=t._context;return{data:{get:function t(r){if(r!=null){return j(e.state||{},r)}else{return e.state||{}}},set:function t(r,n){var i=a({},e.state);$(i,r,n);e.setState(i)}}}}function A(t){if(V(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 P(t.apply(this,n),{instance:this.data})}}else{return function(){return P(t,{instance:this.data})}}}function D(t){var e=t[0],r=t[1],n=t[2];if(!n)return;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().replace(/\-/g,":")}}}var G=e.utils;var q=G.isObject;var B=G.extend;var L=e.Vdt.miss.h;var W=void 0;var z=void 0;var Z=[];var H=function(e){s(r,e);function r(t,n){i(this,r);if(n){var o={};var a=S(t,n,o);var s=u(this,e.call(this,a));o.instance=s;s.__promises=n.__promises||Z;s.mountedQueue=n.__parent&&n.__parent.mountedQueue;s.vNode=L(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))}s._triggerFlagStack=[];var p=void 0;Object.defineProperty(s,"element",{get:function t(){if(!this.__isUpdating&&p&&p.nodeType===8&&p.nodeValue===x){return p._realElement||p}return p},set:function t(e){p=e},configurable:true,enumerable:true});return u(s)}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){var i=this.__isUpdating;this.__isUpdating=true;this.refs=this.vdt.widgets||{};this.__pushGetChildContext(n);var o=e.prototype.init.call(this,r,n);this.__popGetChildContext();this.__isUpdating=i;return o};r.prototype.update=function t(r,n,i){var o=this;var t=function t(){var a=o.__isUpdating;o.__isUpdating=true;var s=!a&&!o.__getChildContext;if(s){o.__pushGetChildContext(n||o.vNode)}var u=e.prototype.update.call(o,r,n,i);if(s){o.__popGetChildContext()}o.__isUpdating=a;return u};if(!this._isReact)return t();this.__initMountedQueue();var a=t();this.__triggerMountedQueue();return a};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 a({},t,{__parent:i})}}this.__parentInstance=n};r.prototype.__popGetChildContext=function t(){if(this.__parentInstance){this.__parentInstance.getChildContext=this.__getChildContext;this.__getChildContext=null}};r.prototype.componentDidMount=function t(){var e=this;this.__initMountedQueue();this.inited=true;this.parentVNode=this.vNode.parentVNode=this.context.__parent&&this.context.__parent.vNode;var r=this.init(null,this.vNode);var n=this._placeholder;var i=n.parentElement;this.parentDom=i;r[W]=n[W];r[z]=n[z];Object.defineProperty(n,"parentNode",{value:i});i.replaceChild(r,n);n._realElement=r;if(!i._hasRewrite){var o=i.removeChild;i.removeChild=function(t){o.call(this,t._realElement||t)};var a=i.insertBefore;i.insertBefore=function(t,e){a.call(this,t,e._realElement||e)};i._hasRewrite=true}this.mountedQueue.push(function(){e.mount()});this.__triggerMountedQueue()};r.prototype.componentWillUnmount=function t(){this.destroy()};r.prototype.componentDidUpdate=function t(){this.__initMountedQueue();var e=L(this.constructor,S(this.props,this.context,{instance:this}));var r=this.vNode;e.children=this;this.vNode=e;this.parentVNode=e.parentVNode=this.context.__parent&&this.context.__parent.vNode;this.update(r,e);this.__triggerMountedQueue()};r.prototype.__ref=function t(e){this._placeholder=e;if(!W){var r=Object.keys(e);W=r[0];z=r[1]}};r.prototype.render=function e(){this.__providers=new Map;var r=this._reactInternalFiber;while(r=r.return){if(r.tag===10){var n=r.type;this.__providers.set(n,n._context._currentValue)}}return t.createElement("i",{ref:this.__ref})};r.prototype.__initMountedQueue=function t(){this._triggerFlagStack.push(this._shouldTrigger);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){p.all(this.__promises).then(function(){Z=[];e._triggerMountedQueue()})}this._shouldTrigger=this._triggerFlagStack.pop()};o(r,[{key:"isMounted",get:function t(){return this.mounted}}]);return r}(e);H.functionalWrapper=m;H.normalize=P;H.$$cid="IntactReact";H.prototype.isReactComponent={};H.contextTypes={_context:g,__parent:g,__promises:g,router:g};H.childContextTypes={__parent:g,__promises:g};if(!Object.setPrototypeOf){B(H,e);if(!H.template){H.template=e.template}}return H}); |
{ | ||
"name": "intact-react", | ||
"version": "1.1.19", | ||
"version": "1.1.20", | ||
"description": "A compatibility layer for running intact component in react v16", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -240,2 +240,12 @@ import React from 'react'; | ||
render() { | ||
// save all context.Provider | ||
this.__providers = new Map(); | ||
let returnFiber = this._reactInternalFiber; | ||
while (returnFiber = returnFiber.return) { | ||
// is ContextProvider | ||
if (returnFiber.tag === 10) { | ||
const type = returnFiber.type; | ||
this.__providers.set(type, type._context._currentValue); | ||
} | ||
} | ||
return React.createElement('i', { | ||
@@ -242,0 +252,0 @@ ref: this.__ref |
import ReactDOM from 'react-dom'; | ||
import FakePromise from './FakePromise'; | ||
import {noop} from './functionalWrapper'; | ||
import React from 'react'; | ||
@@ -65,3 +66,3 @@ const ignorePropRegExp = /_ev[A-Z]/; | ||
_render(nextVNode) { | ||
const vNode = this._addProps(nextVNode); | ||
let vNode = this._addProps(nextVNode); | ||
const placeholder = this.placeholder; | ||
@@ -88,23 +89,24 @@ | ||
} | ||
// if there are providers, pass it to subtree | ||
const providers = parentComponent.__providers; | ||
providers.forEach((value, provider) => { | ||
vNode = React.createElement(provider, {value}, vNode); | ||
}); | ||
const promise = new FakePromise(resolve => { | ||
// the parentComponent should always be valid | ||
// if (parentComponent && parentComponent._reactInternalFiber !== undefined) { | ||
ReactDOM.unstable_renderSubtreeIntoContainer( | ||
parentComponent, | ||
vNode, | ||
placeholder, | ||
// this.parentDom, | ||
function() { | ||
// if the parentVNode is a Intact component, it indicates that | ||
// the Wrapper node is returned by parent component directly | ||
// in this case we must fix the element property of parent component | ||
// 3 is textNode | ||
const dom = this && this.nodeType === 3 ? this : ReactDOM.findDOMNode(this); | ||
placeholder._realElement = dom; | ||
resolve(); | ||
} | ||
); | ||
// } else { | ||
// ReactDOM.render(vNode, this.placeholder, resolve); | ||
// } | ||
ReactDOM.unstable_renderSubtreeIntoContainer( | ||
parentComponent, | ||
vNode, | ||
placeholder, | ||
// this.parentDom, | ||
function() { | ||
// if the parentVNode is a Intact component, it indicates that | ||
// the Wrapper node is returned by parent component directly | ||
// in this case we must fix the element property of parent component. | ||
// 3 is textNode | ||
const dom = this && this.nodeType === 3 ? this : ReactDOM.findDOMNode(this); | ||
placeholder._realElement = dom; | ||
resolve(); | ||
} | ||
); | ||
}); | ||
@@ -111,0 +113,0 @@ parentComponent.__promises.push(promise); |
@@ -1185,9 +1185,20 @@ import Intact from '../index'; | ||
const Context = React.createContext(); | ||
const Test = createIntactComponent(`<div>{self.get('show') ? self.get('children') : null}</div>`); | ||
let test; | ||
function Parent(props) { | ||
return ( | ||
<Context.Provider value="test"> | ||
<ChildrenIntactComponent> | ||
<Child /> | ||
</ChildrenIntactComponent> | ||
</Context.Provider> | ||
<div> | ||
<Context.Provider value={props.value}> | ||
<ChildrenIntactComponent> | ||
<Child /> | ||
<header> | ||
<Test ref={i => test = i}> | ||
<Child /> | ||
</Test> | ||
</header> | ||
<div>hello</div> | ||
</ChildrenIntactComponent> | ||
</Context.Provider> | ||
<Child /> | ||
</div> | ||
); | ||
@@ -1199,3 +1210,2 @@ } | ||
{value => { | ||
debugger; | ||
return <div>{value}</div> | ||
@@ -1206,4 +1216,29 @@ }} | ||
} | ||
render(<Parent />); | ||
render(<Parent value="a" />); | ||
expect(container.innerHTML).to.eq('<div><div><div>a</div><header><div></div></header><div>hello</div></div><div></div></div>'); | ||
ReactDOM.render(<Parent value="b" />, container); | ||
expect(container.innerHTML).to.eq('<div><div><div>b</div><header><div></div></header><div>hello</div></div><div></div></div>'); | ||
test.set('show', true); | ||
expect(container.innerHTML).to.eq('<div><div><div>b</div><header><div><div>b</div></div></header><div>hello</div></div><div></div></div>'); | ||
}); | ||
it('nested new context api should keep order', () => { | ||
const Context = React.createContext(); | ||
render( | ||
<Context.Provider value="a"> | ||
<ChildrenIntactComponent> | ||
<Context.Provider value="b"> | ||
<Context.Provider value="c"> | ||
<ChildrenIntactComponent> | ||
<Context.Consumer> | ||
{value => <div>{value}</div>} | ||
</Context.Consumer> | ||
</ChildrenIntactComponent> | ||
</Context.Provider> | ||
</Context.Provider> | ||
</ChildrenIntactComponent> | ||
</Context.Provider> | ||
); | ||
expect(container.innerHTML).to.eq('<div><div><div>c</div></div></div>'); | ||
}); | ||
}); |
150418
3473