Comparing version 1.0.0-beta.11 to 1.0.0-beta.12
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).Rax={})}(this,function(t){"use strict";var k={mountID:1,owner:null,isUpdating:!1,rootComponents:{},rootInstances:{},driver:null};function h(t,e,n,r,i){return{type:t,key:e,ref:n,props:r,_owner:i}}function f(t){if(null==t)return t;var e=[];return function t(e,n){if(Array.isArray(e))for(var r=0,i=e.length;r<i;r++)t(e[r],n);else n.push(e)}(t,e),1===e.length&&(e=e[0]),e}var p={key:!0,ref:!0};function l(t,e,n){if(null==t)throw Error("createElement: type should not be null or undefined."+function(){var t=k.owner;if(t){var e=t.getName();if(e)return" Check the render method of `"+e+"`."}return""}());var r,i={},o=null,u=null,a=k.owner;if(null!=e)for(r in u=void 0===e.ref?null:e.ref,o=void 0===e.key?null:String(e.key),"string"!=typeof u||a||console.warn("createElement: adding a string ref outside the component’s render() method."),e)p[r]||(i[r]=e[r]);var s=arguments.length-2;if(0<s)if(1!==s||Array.isArray(n)){var l=n;if(1<s){l=new Array(s);for(var c=0;c<s;c++)l[c]=arguments[c+2]}i.children=f(l)}else i.children=n;if(t&&t.defaultProps){var d=t.defaultProps;for(r in d)void 0===i[r]&&(i[r]=d[r])}return new h(t,o,u,i,a)}function u(t,e){t.prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e}var a=function(){function t(t,e){this.props=t,this.context=e,this.refs={}}var e=t.prototype;return e.setState=function(t,e){this.updater.setState(this,t,e)},e.forceUpdate=function(t){this.updater.forceUpdate(this,t)},t}(),s=function(){function t(t){this.handlers=[],this.value=t}var e=t.prototype;return e.on=function(t){this.handlers.push(t)},e.off=function(e){this.handlers=this.handlers.filter(function(t){return t!==e})},e.emit=function(){var e=this;this.handlers.forEach(function(t){return t(e.value)})},t}(),c=0;var e,n=null,r="undefined"==typeof setImmediate?function(t){return setTimeout(t,0)}:setImmediate,i="undefined"==typeof clearImmediate?clearTimeout:clearImmediate,o=[];function d(){var t=o;o=[],t.forEach(function(t){return t()}),t=null,n()}var v=function(t){0===o.length&&(e=r(d)),o.push(t)};function _(){0!==o.length&&(i(e),d())}function m(){var t=k.owner._instance;if(t)return t;throw Error("Hooks can only be called inside a component.")}function g(t,e){for(var n=0;n<t.length;n++){var r=t[n],i=e[n];if((r!==i||0===r&&1/r!=1/i)&&(r==r||i==i))return!1}return!0}function C(t,e){y(t,e)}function y(t,e,i){var n=m(),o=n.getHookID(),u=n.getHooks();if(e=null!=e?e:[t],u[o]){var r=u[o],a=r.create,s=r.inputs;r.inputs=e,r.prevInputs=s,a.current=t}else{var l=function t(e){if(!e&&i)return v(function(){return t(!0)});var n=t.current;if(n){var r=k.isUpdating;k.isUpdating=!0,c.current=n(),t.current=null,k.isUpdating=r}},c=function t(e){if(!e&&i)return v(function(){return t(!0)});var n=t.current;if(n){var r=k.isUpdating;k.isUpdating=!0,n(),t.current=null,k.isUpdating=r}};l.current=t,u[o]={create:l,destory:c,prevInputs:e,inputs:e},n.didMount.push(l),n.willUnmount.push(c),n.didUpdate.push(function(){var t=u[o],e=t.prevInputs,n=t.inputs,r=t.create;null!=e&&g(n,e)||(c(),r())})}}function N(t,e){var n=m(),r=n.getHookID(),i=n.getHooks();if(i[r]){var o=i[r];g(e,o[1])||(o[0]=t())}else i[r]=[t(),e];return i[r][0]}var x=Object.prototype.hasOwnProperty;function I(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function w(t,e){if(I(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(var i=0;i<n.length;i++)if(!x.call(e,n[i])||!I(t[n[i]],e[n[i]]))return!1;return!0}var b=function(){function t(){this._currentElement=null}var e=t.prototype;return e.mountComponent=function(t,e,n,r){this._parent=t,this._parentInstance=e,this._context=n;var i={_internal:this},o=this.getNativeNode();return r?r(o,t):k.driver.appendChild(o,t),i},e.unmountComponent=function(t){this._nativeNode&&!t&&k.driver.removeChild(this._nativeNode,this._parent),this._nativeNode=null,this._parent=null,this._parentInstance=null,this._context=null},e.updateComponent=function(){},e.getNativeNode=function(){return null==this._nativeNode&&(this._nativeNode=k.driver.createEmpty()),this._nativeNode},t}(),E={update:function(t,e,n){var r=t&&t.ref||null,i=e&&e.ref||null;r!==i&&(null!=r&&this.detach(t._owner,r,n),null!=i&&this.attach(e._owner,i,n))},attach:function(t,e,n){if(!t)throw Error("Multiple version of Rax used in project.");var r=n.getPublicInstance();"function"==typeof e?e(r):"object"==typeof e?e.current=r:t._instance.refs[e]=r},detach:function(t,e,n){if("function"==typeof e)e(null);else{var r=n.getPublicInstance();"object"==typeof e&&e.current===r?e.current=null:t._instance.refs[e]===r&&delete t._instance.refs[e]}}};function D(t){var e;return null==t||!1===t||!0===t?e=new k.Empty:Array.isArray(t)?e=new k.Fragment(t):"object"==typeof t&&t.type?e="string"==typeof t.type?new k.Native(t):new k.Composite(t):"string"==typeof t||"number"==typeof t?e=new k.Text(t):U(t),e._mountIndex=0,e}function U(t){throw Error("Invalid element type: "+t+". (current: "+("object"==typeof t&&Object.keys(t)||typeof t)+")")}function S(t,e){var n=null===t,r=null===e;if(n||r)return n===r;var i=typeof t,o=typeof e;return"string"===i||"number"===i?"string"===o||"number"===o:"object"===i&&"object"===o&&t.type===e.type&&t.key===e.key}var A=function(t,e,n){var r=e&&e.key,i="."+n.toString(36);if("string"!=typeof r)return i;var o="$"+r,u=void 0===t[o];return u||console.warn('Encountered two children with the same key "'+r+'".'),u?o:i},P=1,R=function(e){function t(){var t;return(t=e.call(this)||this).state={element:[]},t.rootID=P++,t}u(t,e);var n=t.prototype;return n.getPublicInstance=function(){return this.getRenderedComponent().getPublicInstance()},n.getRenderedComponent=function(){return this._internal._renderedComponent},n.update=function(t){this.setState({element:t})},n.render=function(){return this.state.element},t}(a),j="__r",H={set:function(t,e){t[j]||(t[j]=e).rootID&&(k.rootInstances[e.rootID]=e,k.rootComponents[e.rootID]=e._internal)},get:function(t){return t[j]},remove:function(t){var e=this.get(t);e&&(t[j]=null,e.rootID&&(delete k.rootComponents[e.rootID],delete k.rootInstances[e.rootID]))},mount:function(t,e,n){var r,i=k.driver;if(i.beforeRender&&i.beforeRender(),null==e&&(e=i.createBody()),n){var o=n._internal;r=o._processChildContext(o._context)}var u=this.get(e);if(u&&u.rootID)return r&&(u._internal._penddingContext=r),u.update(t),u;var a=r||{},s=D(l(R)).mountComponent(e,null,a);return this.set(e,s),s.update(t),i.afterRender&&i.afterRender(s),s}},O="style",M="children",W=/^on[A-Z]/,F=function(){function t(t){this._currentElement=t}var e=t.prototype;return e.mountComponent=function(e,t,n,r){var i=this;this._parent=e,this._parentInstance=t,this._context=n,this._mountID=k.mountID++;var o=this._currentElement,u=o.props,a=o.type,s=u.children,l=u.append||"tree";this._prevStyleCopy=Object.assign({},u.style);var c={_internal:this,type:a,props:u};this._instance=c;var d=function(){var t=i.getNativeNode();r?r(t,e):k.driver.appendChild(t,e)},h=function(){null!=s&&i.mountChildren(s,n)};return"tree"===l?(h(),d()):(d(),h()),o&&o.ref&&E.attach(o._owner,o.ref,this),c},e.mountChildren=function(t,e){Array.isArray(t)||(t=[t]);var n=this.getNativeNode();return this._mountChildren(n,t,e)},e._mountChildren=function(i,t,o,u){var a=this,s=this._renderedChildren={};return t.map(function(t,e){var n=D(t),r=A(s,t,e);return(s[r]=n)._mountIndex=e,n.mountComponent(i,a._instance,o,u)})},e.unmountChildren=function(t){var e=this._renderedChildren;if(e){for(var n in e){e[n].unmountComponent(t)}this._renderedChildren=null}},e.unmountComponent=function(t){if(this._nativeNode){var e=this._currentElement.ref;e&&E.detach(this._currentElement._owner,e,this),H.remove(this._nativeNode),t||k.driver.removeChild(this._nativeNode,this._parent)}this.unmountChildren(t),this._currentElement=null,this._nativeNode=null,this._parent=null,this._parentInstance=null,this._context=null,this._instance=null,this._prevStyleCopy=null},e.updateComponent=function(t,e,n,r){this._currentElement=e,E.update(t,e,this);var i=t.props,o=e.props;this.updateProperties(i,o),this.updateChildren(o.children,r)},e.updateProperties=function(t,e){var n,r,i,o=k.driver,u=this.getNativeNode();for(n in t)if(n!==M&&null!=t[n]&&!e.hasOwnProperty(n))if(n===O){var a=this._prevStyleCopy;for(r in a)(i=i||{})[r]="";this._prevStyleCopy=null}else if(W.test(n)){var s=t[n];"function"==typeof s&&o.removeEventListener(u,n.slice(2).toLowerCase(),s)}else o.removeAttribute(u,n,t[n]);for(n in e){var l=e[n],c=n===O?this._prevStyleCopy:null!=t?t[n]:void 0;if(n!==M&&c!==l&&(null!=l||null!=c))if(n===O)if(l?l=this._prevStyleCopy=Object.assign({},l):this._prevStyleCopy=null,null!=c){for(r in c)l&&l[r]||((i=i||{})[r]="");for(r in l)c[r]!==l[r]&&((i=i||{})[r]=l[r])}else i=l;else if(W.test(n)){var d=n.slice(2).toLowerCase();"function"==typeof c&&o.removeEventListener(u,d,c,e),"function"==typeof l&&o.addEventListener(u,d,l,e)}else null!=l?o.setAttribute(u,n,l):o.removeAttribute(u,n,t[n])}i&&o.setStyles(u,i)},e.updateChildren=function(t,e){var n=this._renderedChildren,o=k.driver;if(null!=t||null!=n){var r,u,i,a={};if(null!=t){Array.isArray(t)||(t=[t]);for(var s=0,l=t.length;s<l;s++){var c=t[s],d=A(a,c,s),h=n&&n[d],f=h&&h._currentElement,p=h&&h._context;null!=h&&S(f,c)?(f===c&&p===e||h.updateComponent(f,c,e,e),a[d]=h):(h&&(h._unmount=!0),a[d]=D(c))}}if(null!=n)for(var v in n){var _=n[v],m=_._unmount||!a[v];r?m&&_.unmountComponent():(i=m,u=(r=_).getNativeNode(),Array.isArray(u)&&(u=u[0]))}if(null!=a){var g=function(t,e){if(Array.isArray(t)||(t=[t]),y)for(var n=t.length-1;0<=n;n--)o.insertAfter(t[n],y);else if(u)for(var r=0;r<t.length;r++)o.insertBefore(t[r],u);else if(e)for(var i=0;i<t.length;i++)o.appendChild(t[i],e)},C=0,y=null,N=[];for(var x in a){var I=a[x],w=n&&n[x];if(w===I){var b=w.getNativeNode();w._mountIndex!==C&&g(b)}else{var E=this.getNativeNode();Array.isArray(E)&&(E=this._parent),I.mountComponent(E,this._instance,e,g)}I._mountIndex=C++,y=I.getNativeNode(),N=N.concat(y),Array.isArray(y)&&(y=y[y.length-1])}if(Array.isArray(this._nativeNode)){this._nativeNode.splice(0,this._nativeNode.length);for(var U=0;U<N.length;U++)this._nativeNode.push(N[U])}}i&&r.unmountComponent(),this._renderedChildren=a}},e.getNativeNode=function(){return null==this._nativeNode&&(this._nativeNode=k.driver.createElement(this._instance),H.set(this._nativeNode,this._instance)),this._nativeNode},e.getPublicInstance=function(){return this.getNativeNode()},e.getName=function(){return this._currentElement.type},t}(),T=function(){function t(t){this._currentElement=t,this._text=String(t)}var e=t.prototype;return e.mountComponent=function(t,e,n,r){this._parent=t,this._parentInstance=e,this._context=n,this._mountID=k.mountID++;var i=this.getNativeNode();return r?r(i,t):k.driver.appendChild(i,t),{_internal:this}},e.unmountComponent=function(t){this._nativeNode&&!t&&k.driver.removeChild(this._nativeNode,this._parent),this._currentElement=null,this._nativeNode=null,this._parent=null,this._parentInstance=null,this._context=null,this._text=null},e.updateComponent=function(t,e,n){t!==e&&(this._currentElement=e,this._text=String(e),k.driver.updateText(this.getNativeNode(),this._text))},e.getNativeNode=function(){return null==this._nativeNode&&(this._nativeNode=k.driver.createText(this._text)),this._nativeNode},t}(),L=function(n){function t(t,e){var r;(r=n.call(this)||this)._render=t,r._hookID=0,r._reRenders=0,r._hooks={},r.didMount=[],r.didUpdate=[],r.willUnmount=[],r.isScheduled=!1,t.forwardRef&&(r.prevForwardRef=r.forwardRef=e);var i=t.compares;return i&&(r.shouldComponentUpdate=function(t){for(var e=!0,n=i.length-1;-1<n&&!(e=i[n](r.props,t));n--);return!e||r.prevForwardRef!==r.forwardRef}),r}u(t,n);var e=t.prototype;return e.getHooks=function(){return this._hooks},e.getHookID=function(){return++this._hookID},e.readContext=function(t){var e=this,n=t.Provider,r=this._internal._context[n.contextProp];if(r){var i=this._internal._mountID;if(!r[i]){r[i]={};var o=function(t){t!==r[i].renderedContext&&e.update()};r.on(o),this.willUnmount.push(function(){delete r[i],r.off(o)})}return r[i].renderedContext=r.value}return n.defaultValue},e.componentDidMount=function(){this.didMount.forEach(function(t){return t()})},e.componentDidUpdate=function(){this.didUpdate.forEach(function(t){return t()})},e.componentWillUnmount=function(){this.willUnmount.forEach(function(t){return t()})},e.update=function(){this.forceUpdate()},e.render=function(){this._hookID=0,this._reRenders=0,this.isScheduled=!1;for(var t=this._render(this.props,this.forwardRef?this.forwardRef:this.context);this.isScheduled;){if(this._reRenders++,24<this._reRenders)throw Error("Too many re-renders, the number of renders is limited to prevent an infinite loop.");this._hookID=0,this.isScheduled=!1,t=this._render(this.props,this.forwardRef?this.forwardRef:this.context)}return t},t}(a),Q=[];function B(t){return t._pendingCallbacks}function V(t,e){return t._pendingCallbacks=e}function Z(t){return t._pendingStateQueue}function $(t,e){if(t)for(var n=0;n<t.length;n++)t[n].call(e)}function q(t){var e=t._internal;if(e){k.isUpdating=!0;var n=B(e);V(e,null);var r=e._currentElement,i=e._context,o=e._penddingContext||i;e._penddingContext=void 0,(Z(e)||e._isPendingForceUpdate)&&e.updateComponent(r,r,i,o),$(n,t),k.isUpdating=!1}}function z(t,e){return e._internal._mountID-t._internal._mountID}function G(){if(!k.isUpdating)for(var t,e;0<Q.length;)for(_(),t=Q.sort(z),Q=[];e=t.pop();)q(e)}function J(t){Q.indexOf(t)<0&&Q.push(t),G()}function K(t,e,n){var r=t._internal;if(r){var i,o;!k.isUpdating&&_(),n&&(o=n,(B(i=r)||V(i,[])).push(o));var u,a,s,l=r._renderedComponent;e?(a=e,(Z(u=r)||(s=[],u._pendingStateQueue=s)).push(a),!r._isPendingState&&l&&J(t)):(r._isPendingForceUpdate=!0,l&&J(t))}}n=G;var X={setState:K,forceUpdate:function(t,e){K(t,null,e)},runCallbacks:$};function Y(t,e,n){try{return t()}catch(t){n?n(t):tt(e,t)}}function tt(t,e){for(var n;t;){var r=t._internal;if("function"==typeof t.componentDidCatch){n=t;break}if(!r||!r._parentInstance)break;t=r._parentInstance}if(n){var i=n._internal;if(i)(i._pendingCallbacks||(i._pendingCallbacks=[])).push(function(){return n.componentDidCatch(e)})}else setTimeout(function(){throw e},0)}var et=function(){function t(t){this._currentElement=t}var e=t.prototype;return e.getName=function(){var t=this._currentElement.type,e=this._instance,n=e&&e.constructor;return t.displayName||n&&n.displayName||t.name||n&&n.name||null},e.mountComponent=function(t,e,n,r){this._parent=t,this._parentInstance=e,this._context=n,this._mountID=k.mountID++,this._updateCount=0;var i,o,u=this._currentElement,a=u.type,s=u.ref,l=u.props,c=a.prototype,d=this._processContext(n);try{c&&c.render?i=new a(l,d):"function"==typeof a?i=new L(a,s):U(a)}catch(t){return tt(e,t),i}i.props=l,i.context=d,i.refs={},i.updater=X;var h=((i._internal=this)._instance=i).state;void 0===h&&(i.state=h=null);var f=null,p=function(t){f=t};i.componentWillMount&&Y(function(){i.componentWillMount()},i,p),null==o&&(k.owner=this,i.state=this._processPendingState(l,d),Y(function(){o=i.render()},i,p),k.owner=null),this._renderedComponent=D(o),this._renderedComponent.mountComponent(this._parent,i,this._processChildContext(n),r),f&&tt(i,f),!u.type.forwardRef&&s&&E.attach(u._owner,s,this),i.componentDidMount&&Y(function(){i.componentDidMount()},i);var v=this._pendingCallbacks;return v&&(this._pendingCallbacks=null,X.runCallbacks(v,i)),i},e.unmountComponent=function(t){var e=this._instance;if(e){if(e.componentWillUnmount&&Y(function(){e.componentWillUnmount()},e),(e._internal=null)!=this._renderedComponent){var n=this._currentElement,r=n.ref;!n.type.forwardRef&&r&&E.detach(n._owner,r,this),this._renderedComponent.unmountComponent(t),this._renderedComponent=null,this._instance=null}this._currentElement=null,this._parentInstance=null,this._pendingStateQueue=null,this._isPendingForceUpdate=!1,this._context=null}},e._processContext=function(t){var e=this._currentElement.type.contextTypes;if(!e)return{};var n={};for(var r in e)n[r]=t[r];return n},e._processChildContext=function(t){var e=this._instance,n=e.getChildContext&&e.getChildContext();return n?Object.assign({},t,n):t},e._processPendingState=function(t,e){var n=this._instance,r=this._pendingStateQueue;if(!r)return n.state;this._pendingStateQueue=null;for(var i=Object.assign({},n.state),o=0;o<r.length;o++){var u=r[o];Object.assign(i,"function"==typeof u?u.call(n,i,t,e):u)}return i},e.updateComponent=function(t,e,n,r){var i=this._instance;i||console.error("Update component '"+this.getName()+"' that has already been unmounted (or failed to mount).");var o,u,a=!1;this._context===r?o=i.context:(o=this._processContext(r),a=!0),t===e?u=e.props:(u=e.props,a=!0),a&&i.componentWillReceiveProps&&(this._isPendingState=!0,Y(function(){i.componentWillReceiveProps(u,o)},i),this._isPendingState=!1),this._currentElement.type.forwardRef?(i.prevForwardRef=t.ref,i.forwardRef=e.ref):E.update(t,e,this);var s=!0,l=i.props,c=i.state,d=this._processPendingState(u,o);if(this._isPendingForceUpdate||(i.shouldComponentUpdate?s=Y(function(){return i.shouldComponentUpdate(u,d,o)},i):i.isPureComponent&&(s=!w(l,u)||!w(c,d))),s){this._isPendingForceUpdate=!1;var h=i.context;Y(function(){i.componentWillUpdate&&i.componentWillUpdate(u,d,o)},i),this._currentElement=e,this._context=r,i.props=u,i.state=d,i.context=o,this._updateRenderedComponent(r),Y(function(){i.componentDidUpdate&&i.componentDidUpdate(l,c,h)},i),this._updateCount++}else this._currentElement=e,this._context=r,i.props=u,i.state=d,i.context=o;var f=this._pendingCallbacks;f&&(this._pendingCallbacks=null,X.runCallbacks(f,i))},e._updateRenderedComponent=function(t){var e,n=this._renderedComponent,r=n._currentElement,i=this._instance;if(k.owner=this,Y(function(){e=i.render()},i),k.owner=null,S(r,e)){var o=n._context,u=this._processChildContext(t);r===e&&o===u||n.updateComponent(r,e,o,u)}else{var a=n.getNativeNode();n.unmountComponent(!0),this._renderedComponent=D(e),this._renderedComponent.mountComponent(this._parent,i,this._processChildContext(t),function(t,e){Array.isArray(t)||(t=[t]),Array.isArray(a)||(a=[a]);for(var n,r=k.driver,i=0;i<t.length;i++){var o=t[i];a[i]?r.replaceChild(o,a[i]):n?r.insertAfter(o,n):r.appendChild(o,e),n=o}if(t.length<a.length)for(var u=t.length;u<a.length;u++)r.removeChild(a[u])})}},e.getNativeNode=function(){var t=this._renderedComponent;if(t)return t.getNativeNode()},e.getPublicInstance=function(){var t=this._instance;return t instanceof L?null:t},t}(),nt=function(e){function t(t){return e.call(this,t)||this}u(t,e);var n=t.prototype;return n.mountComponent=function(t,e,n,r){this._parent=t,this._parentInstance=e,this._context=n,this._mountID=k.mountID++;var i={_internal:this};this._instance=i;var o=this.getNativeNode(),u=this._currentElement;if(this.mountChildren(u,n),r)r(o,t);else for(var a=0;a<o.length;a++){var s=o[a];k.driver.appendChild(s,t)}return i},n.mountChildren=function(t,e){var n=this.getNativeNode();return this._mountChildren(this._parent,t,e,function(t){Array.isArray(t)||(t=[t]);for(var e=0;e<t.length;e++)n.push(t[e])})},n.unmountComponent=function(t){var e=this._nativeNode;if(e&&(H.remove(e),!t))for(var n=0;n<e.length;n++)k.driver.removeChild(e[n]);this.unmountChildren(!0),this._currentElement=null,this._nativeNode=null,this._parent=null,this._parentInstance=null,this._context=null,this._instance=null},n.updateComponent=function(t,e,n,r){this._currentElement=e,this.updateChildren(this._currentElement,r)},n.getNativeNode=function(){return null==this._nativeNode&&(this._nativeNode=[]),this._nativeNode},n.getPublicInstance=function(){return this.getNativeNode()},n.getName=function(){return"fragment"},t}(F);var rt={Host:k,Instance:H,Element:h,flattenChildren:f};t.createElement=l,t.createRef=function(){return{current:null}},t.createContext=function(i){var t,e,o="__context_"+c+++"__",n=function(e){function t(){var t;return(t=e.call(this)||this).emitter=new s(i),t}u(t,e);var n=t.prototype;return n.getChildContext=function(){var t;return(t={})[o]=this.emitter,t},n.componentWillMount=function(){void 0!==this.props.value&&(this.emitter.value=this.props.value)},n.componentWillReceiveProps=function(t){this.props.value!==t.value&&(this.emitter.value=t.value)},n.componentDidUpdate=function(t){this.props.value!==t.value&&this.emitter.emit()},n.render=function(){return this.props.children},t}(a);n.childContextTypes=((t={})[o]=function(){},t),n.contextProp=o,n.defaultValue=i;var r=function(r){function t(t,e){var n;return(n=r.call(this,t,e)||this).state={value:n.readContext(n.context)},n.onUpdate=function(t){return n.state.value!==t&&n.setState({value:t})},n}u(t,r);var e=t.prototype;return e.readContext=function(t){return t[o]?t[o].value:i},e.componentDidMount=function(){this.context[o]&&this.context[o].on(this.onUpdate)},e.componentWillReceiveProps=function(t,e){var n=this.readContext(e);this.state.value!==n&&this.setState({value:n})},e.componentWillUnmount=function(){this.context[o]&&this.context[o].off(this.onUpdate)},e.render=function(){var t=this.props.children,e=Array.isArray(t)?t[0]:t;if("function"==typeof e)return e(this.state.value)},t}(a);return r.contextTypes=((e={})[o]=function(){},e),{Provider:n,Consumer:r}},t.useState=function(t){var n=m(),r=n.getHookID(),i=n.getHooks();i[r]||("function"==typeof t&&(t=t()),i[r]=[t,function(t){var e=i[r][0];"function"==typeof t&&(t=t(e)),t!==e&&(k.owner&&k.owner._instance===n?(i[r][0]=t,n.isScheduled=!0):(!k.isUpdating&&_(),i[r][0]=t,n.update()))}]);return i[r]},t.useContext=function(t){return m().readContext(t)},t.useEffect=function(t,e){y(t,e,!0)},t.useLayoutEffect=C,t.useRef=function(t){var e=m(),n=e.getHookID(),r=e.getHooks();return r[n]||(r[n]={current:t}),r[n]},t.useCallback=function(t,e){return N(function(){return t},e)},t.useMemo=N,t.useReducer=function(t,e,n){var r=m(),i=r.getHookID(),o=r.getHooks();if(!o[i])return n&&(e=t(e,n)),o[i]=[e,function(t){var e=o[i][2];k.owner&&k.owner._instance===r?(e.push(t),r.isScheduled=!0):(!k.isUpdating&&_(),e.push(t),r.update())},[]];for(var u=o[i],a=u[2],s=u[0],l=0;l<a.length;l++)s=t(s,a[l]);return u[0]=s,u[2]=[],o[i]},t.useImperativeHandle=function(t,e,n){C(function(){return"function"==typeof t?(t(e()),function(){return t(null)}):null!=t?(t.current=e(),function(){t.current=null}):void 0},null!=n?n.concat([t]):[t,e])},t.Fragment=function(t){return t.children},t.memo=function(t,e){return void 0===e&&(e=w),t.compares?t.compares.push(e):t.compares=[e],t},t.render=function(t,e,n,r){"function"==typeof n&&(r=n,n=null),function(t){var e=t.driver;if(t.measurer,k.Empty=b,k.Native=F,k.Text=T,k.Fragment=nt,k.Composite=et,k.driver=e||k.driver,!k.driver)throw Error("Driver not found.")}(n=n||{});var i=H.mount(t,e,n.parent).getPublicInstance();return r&&r.call(i),i},t.version="1.0.0-beta",t.shared=rt,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).Rax={})}(this,function(t){"use strict";var k={mountID:1,owner:null,isUpdating:!1,rootComponents:{},rootInstances:{},driver:null};function p(t,e,n,r,o){return{type:t,key:e,ref:n,props:r,_owner:o}}function d(t){if(null==t)return t;var e=[];return function t(e,n){if(Array.isArray(e))for(var r=0,o=e.length;r<o;r++)t(e[r],n);else n.push(e)}(t,e),1===e.length&&(e=e[0]),e}var h={key:!0,ref:!0};function c(t,e,n){if(null==t)throw Error("createElement: type should not be null or undefined."+function(){var t=k.owner;if(t){var e=t.getName();if(e)return" Check the render method of `"+e+"`."}return""}());var r,o={},i=null,u=null,a=k.owner;if(null!=e)for(r in u=void 0===e.ref?null:e.ref,i=void 0===e.key?null:String(e.key),"string"!=typeof u||a||console.warn("createElement: adding a string ref outside the component’s render() method."),e)h[r]||(o[r]=e[r]);var s=arguments.length-2;if(0<s)if(1!==s||Array.isArray(n)){var c=n;if(1<s){c=new Array(s);for(var l=0;l<s;l++)c[l]=arguments[l+2]}o.children=d(c)}else o.children=n;if(t&&t.defaultProps){var f=t.defaultProps;for(r in f)void 0===o[r]&&(o[r]=f[r])}return new p(t,i,u,o,a)}function u(t,e){t.prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e}var a=function(){function t(t,e){this.props=t,this.context=e,this.refs={}}var e=t.prototype;return e.setState=function(t,e){this.updater.setState(this,t,e)},e.forceUpdate=function(t){this.updater.forceUpdate(this,t)},t}(),s=function(){function t(t){this.handlers=[],this.value=t}var e=t.prototype;return e.on=function(t){this.handlers.push(t)},e.off=function(e){this.handlers=this.handlers.filter(function(t){return t!==e})},e.emit=function(){var e=this;this.handlers.forEach(function(t){return t(e.value)})},t}(),l=0;var e,n=null,r="undefined"==typeof setImmediate?function(t){return setTimeout(t,0)}:setImmediate,o="undefined"==typeof clearImmediate?clearTimeout:clearImmediate,i=[];function f(){var t=i;i=[],t.forEach(function(t){return t()}),t=null,n()}var v=function(t){0===i.length&&(e=r(f)),i.push(t)};function m(){0!==i.length&&(o(e),f())}function _(){var t=k.owner._instance;if(t)return t;throw Error("Hooks can only be called inside a component.")}function y(t,e){for(var n=0;n<t.length;n++){var r=t[n],o=e[n];if((r!==o||0===r&&1/r!=1/o)&&(r==r||o==o))return!1}return!0}function C(t,e){g(t,e)}function g(t,e,o){var n=_(),i=n.getHookID(),u=n.getHooks();if(e=null!=e?e:[t],u[i]){var r=u[i],a=r.create,s=r.inputs;r.inputs=e,r.prevInputs=s,a.current=t}else{var c=function t(e){if(!e&&o)return v(function(){return t(!0)});var n=t.current;if(n){var r=k.isUpdating;k.isUpdating=!0,l.current=n(),t.current=null,k.isUpdating=r}},l=function t(e){if(!e&&o)return v(function(){return t(!0)});var n=t.current;if(n){var r=k.isUpdating;k.isUpdating=!0,n(),t.current=null,k.isUpdating=r}};c.current=t,u[i]={create:c,destory:l,prevInputs:e,inputs:e},n.didMount.push(c),n.willUnmount.push(l),n.didUpdate.push(function(){var t=u[i],e=t.prevInputs,n=t.inputs,r=t.create;null!=e&&y(n,e)||(l(),r())})}}function N(t,e){var n=_(),r=n.getHookID(),o=n.getHooks();if(o[r]){var i=o[r];y(e,i[1])||(i[0]=t())}else o[r]=[t(),e];return o[r][0]}var x=Object.prototype.hasOwnProperty;function w(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function b(t,e){if(w(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(var o=0;o<n.length;o++)if(!x.call(e,n[o])||!w(t[n[o]],e[n[o]]))return!1;return!0}var I=function(){function t(t){this._currentElement=t}var e=t.prototype;return e.initComponent=function(t,e,n){this._parent=t,this._parentInstance=e,this._context=n,this._mountID=k.mountID++},e.destoryComponent=function(){this._currentElement=null,this._nativeNode=null,this._parent=null,this._parentInstance=null,this._context=null,this._instance&&(this._instance._internal=null,this._instance=null)},e.mountComponent=function(t,e,n,r){return this.initComponent(t,e,n),this.mountNativeNode(r),{_internal:this}},e.updateComponent=function(){},e.unmountComponent=function(t){this._nativeNode&&!t&&k.driver.removeChild(this._nativeNode,this._parent),this.destoryComponent()},e.getName=function(){var t=this._currentElement,e=this._instance,n=t&&t.type,r=e&&e.constructor;return n&&n.displayName||r&&r.displayName||n&&n.name||r&&r.name||n||t},e.mountNativeNode=function(t){var e=this.getNativeNode(),n=this._parent;t?t(e,n):k.driver.appendChild(e,n)},e.getNativeNode=function(){return null==this._nativeNode&&(this._nativeNode=this.createNativeNode()),this._nativeNode},e.getPublicInstance=function(){return this.getNativeNode()},t}(),E=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e.prototype.createNativeNode=function(){return k.driver.createEmpty()},e}(I),U={update:function(t,e,n){var r=t&&t.ref||null,o=e&&e.ref||null;r!==o&&(null!=r&&this.detach(t._owner,r,n),null!=o&&this.attach(e._owner,o,n))},attach:function(t,e,n){if(!t)throw Error("Multiple version of Rax used in project.");var r=n.getPublicInstance();"function"==typeof e?e(r):"object"==typeof e?e.current=r:t._instance.refs[e]=r},detach:function(t,e,n){if("function"==typeof e)e(null);else{var r=n.getPublicInstance();"object"==typeof e&&e.current===r?e.current=null:t._instance.refs[e]===r&&delete t._instance.refs[e]}}};function S(t){var e;return null==t||!1===t||!0===t?e=new k.Empty:Array.isArray(t)?e=new k.Fragment(t):"object"==typeof t&&t.type?e="string"==typeof t.type?new k.Native(t):new k.Composite(t):"string"==typeof t||"number"==typeof t?e=new k.Text(String(t)):A(t),e._mountIndex=0,e}function A(t){throw Error("Invalid element type: "+t+". (current: "+("object"==typeof t&&Object.keys(t)||typeof t)+")")}function D(t,e){var n=null===t,r=null===e;if(n||r)return n===r;var o=typeof t,i=typeof e;return"string"===o||"number"===o?"string"===i||"number"===i:"object"===o&&"object"===i&&t.type===e.type&&t.key===e.key}var R=function(t,e,n){var r=e&&e.key,o="."+n.toString(36);if("string"!=typeof r)return o;var i="$"+r,u=void 0===t[i];return u||console.warn('Encountered two children with the same key "'+r+'".'),u?i:o},P=1,j=function(e){function t(){var t;return(t=e.call(this)||this).state={element:[]},t.rootID=P++,t}u(t,e);var n=t.prototype;return n.getPublicInstance=function(){return this.getRenderedComponent().getPublicInstance()},n.getRenderedComponent=function(){return this._internal._renderedComponent},n.update=function(t){this.setState({element:t})},n.render=function(){return this.state.element},t}(a),H="__r",O={set:function(t,e){t[H]||(t[H]=e).rootID&&(k.rootInstances[e.rootID]=e,k.rootComponents[e.rootID]=e._internal)},get:function(t){return t[H]},remove:function(t){var e=this.get(t);e&&(t[H]=null,e.rootID&&(delete k.rootComponents[e.rootID],delete k.rootInstances[e.rootID]))},mount:function(t,e,n){var r,o=k.driver;if(o.beforeRender&&o.beforeRender(),null==e&&(e=o.createBody()),n){var i=n._internal;r=i._processChildContext(i._context)}var u=this.get(e);if(u&&u.rootID)return r&&(u._internal._penddingContext=r),u.update(t),u;var a=r||{},s=S(c(j)).mountComponent(e,null,a);return this.set(e,s),s.update(t),o.afterRender&&o.afterRender(s),s}},M="style",W="children",F=/^on[A-Z]/,T=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var n=e.prototype;return n.mountComponent=function(e,t,n,r){var o=this;this.initComponent(e,t,n);var i=this._currentElement,u=i.props,a=i.type,s=u.children,c=u.append||"tree";this._prevStyleCopy=Object.assign({},u.style);var l={_internal:this,type:a,props:u};this._instance=l;var f=function(){var t=o.getNativeNode();r?r(t,e):k.driver.appendChild(t,e)},p=function(){null!=s&&o.mountChildren(s,n)};return"tree"===c?(p(),f()):(f(),p()),i&&i.ref&&U.attach(i._owner,i.ref,this),l},n.mountChildren=function(t,e){Array.isArray(t)||(t=[t]);var n=this.getNativeNode();return this._mountChildren(n,t,e)},n._mountChildren=function(o,t,i,u){var a=this,s=this._renderedChildren={};return t.map(function(t,e){var n=S(t),r=R(s,t,e);return(s[r]=n)._mountIndex=e,n.mountComponent(o,a._instance,i,u)})},n.unmountChildren=function(t){var e=this._renderedChildren;if(e){for(var n in e){e[n].unmountComponent(t)}this._renderedChildren=null}},n.unmountComponent=function(t){if(this._nativeNode){var e=this._currentElement.ref;e&&U.detach(this._currentElement._owner,e,this),O.remove(this._nativeNode),t||k.driver.removeChild(this._nativeNode,this._parent)}this.unmountChildren(t),this._prevStyleCopy=null,this.destoryComponent()},n.updateComponent=function(t,e,n,r){this._currentElement=e,U.update(t,e,this);var o=t.props,i=e.props;this.updateProperties(o,i),this.updateChildren(i.children,r)},n.updateProperties=function(t,e){var n,r,o,i=k.driver,u=this.getNativeNode();for(n in t)if(n!==W&&null!=t[n]&&!e.hasOwnProperty(n))if(n===M){var a=this._prevStyleCopy;for(r in a)(o=o||{})[r]="";this._prevStyleCopy=null}else if(F.test(n)){var s=t[n];"function"==typeof s&&i.removeEventListener(u,n.slice(2).toLowerCase(),s)}else i.removeAttribute(u,n,t[n]);for(n in e){var c=e[n],l=n===M?this._prevStyleCopy:null!=t?t[n]:void 0;if(n!==W&&l!==c&&(null!=c||null!=l))if(n===M)if(c?c=this._prevStyleCopy=Object.assign({},c):this._prevStyleCopy=null,null!=l){for(r in l)c&&c[r]||((o=o||{})[r]="");for(r in c)l[r]!==c[r]&&((o=o||{})[r]=c[r])}else o=c;else if(F.test(n)){var f=n.slice(2).toLowerCase();"function"==typeof l&&i.removeEventListener(u,f,l,e),"function"==typeof c&&i.addEventListener(u,f,c,e)}else null!=c?i.setAttribute(u,n,c):i.removeAttribute(u,n,t[n])}o&&i.setStyles(u,o)},n.updateChildren=function(t,e){var n=this._renderedChildren,i=k.driver;if(null!=t||null!=n){var r,u,o,a={};if(null!=t){Array.isArray(t)||(t=[t]);for(var s=0,c=t.length;s<c;s++){var l=t[s],f=R(a,l,s),p=n&&n[f],d=p&&p._currentElement,h=p&&p._context;null!=p&&D(d,l)?(d===l&&h===e||p.updateComponent(d,l,e,e),a[f]=p):(p&&(p._unmount=!0),a[f]=S(l))}}if(null!=n)for(var v in n){var m=n[v],_=m._unmount||!a[v];r?_&&m.unmountComponent():(o=_,u=(r=m).getNativeNode(),Array.isArray(u)&&(u=u[0]))}if(null!=a){var y=function(t,e){if(Array.isArray(t)||(t=[t]),g)for(var n=t.length-1;0<=n;n--)i.insertAfter(t[n],g);else if(u)for(var r=0;r<t.length;r++)i.insertBefore(t[r],u);else if(e)for(var o=0;o<t.length;o++)i.appendChild(t[o],e)},C=0,g=null,N=[];for(var x in a){var w=a[x],b=n&&n[x];if(b===w){var I=b.getNativeNode();b._mountIndex!==C&&y(I)}else{var E=this.getNativeNode();Array.isArray(E)&&(E=this._parent),w.mountComponent(E,this._instance,e,y)}w._mountIndex=C++,g=w.getNativeNode(),N=N.concat(g),Array.isArray(g)&&(g=g[g.length-1])}if(Array.isArray(this._nativeNode)){this._nativeNode.splice(0,this._nativeNode.length);for(var U=0;U<N.length;U++)this._nativeNode.push(N[U])}}o&&r.unmountComponent(),this._renderedChildren=a}},n.createNativeNode=function(){var t=k.driver.createElement(this._instance);return O.set(t,this._instance),t},e}(I),L=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var n=e.prototype;return n.updateComponent=function(t,e,n){t!==(e=String(e))&&(this._currentElement=e,k.driver.updateText(this.getNativeNode(),this._currentElement))},n.createNativeNode=function(){return k.driver.createText(this._currentElement)},e}(I),Q=function(n){function t(t,e){var r;(r=n.call(this)||this)._render=t,r._hookID=0,r._reRenders=0,r._hooks={},r.didMount=[],r.didUpdate=[],r.willUnmount=[],r.isScheduled=!1,t.forwardRef&&(r.prevForwardRef=r.forwardRef=e);var o=t.compares;return o&&(r.shouldComponentUpdate=function(t){for(var e=!0,n=o.length-1;-1<n&&!(e=o[n](r.props,t));n--);return!e||r.prevForwardRef!==r.forwardRef}),r}u(t,n);var e=t.prototype;return e.getHooks=function(){return this._hooks},e.getHookID=function(){return++this._hookID},e.readContext=function(t){var e=this,n=t.Provider,r=this._internal._context[n.contextProp];if(r){var o=this._internal._mountID;if(!r[o]){r[o]={};var i=function(t){t!==r[o].renderedContext&&e.update()};r.on(i),this.willUnmount.push(function(){delete r[o],r.off(i)})}return r[o].renderedContext=r.value}return n.defaultValue},e.componentDidMount=function(){this.didMount.forEach(function(t){return t()})},e.componentDidUpdate=function(){this.didUpdate.forEach(function(t){return t()})},e.componentWillUnmount=function(){this.willUnmount.forEach(function(t){return t()})},e.update=function(){this.forceUpdate()},e.render=function(){this._hookID=0,this._reRenders=0,this.isScheduled=!1;for(var t=this._render(this.props,this.forwardRef?this.forwardRef:this.context);this.isScheduled;){if(this._reRenders++,24<this._reRenders)throw Error("Too many re-renders, the number of renders is limited to prevent an infinite loop.");this._hookID=0,this.isScheduled=!1,t=this._render(this.props,this.forwardRef?this.forwardRef:this.context)}return t},t}(a),B=[];function V(t){return t._pendingCallbacks}function Z(t,e){return t._pendingCallbacks=e}function $(t){return t._pendingStateQueue}function q(t,e){if(t)for(var n=0;n<t.length;n++)t[n].call(e)}function z(t){var e=t._internal;if(e){k.isUpdating=!0;var n=V(e);Z(e,null);var r=e._currentElement,o=e._context,i=e._penddingContext||o;e._penddingContext=void 0,($(e)||e._isPendingForceUpdate)&&e.updateComponent(r,r,o,i),q(n,t),k.isUpdating=!1}}function G(t,e){return e._internal._mountID-t._internal._mountID}function J(){if(!k.isUpdating)for(var t,e;0<B.length;)for(m(),t=B.sort(G),B=[];e=t.pop();)z(e)}function K(t){B.indexOf(t)<0&&B.push(t),J()}function X(t,e,n){var r=t._internal;if(r){var o,i;!k.isUpdating&&m(),n&&(i=n,(V(o=r)||Z(o,[])).push(i));var u,a,s,c=r._renderedComponent;e?(a=e,($(u=r)||(s=[],u._pendingStateQueue=s)).push(a),!r._isPendingState&&c&&K(t)):(r._isPendingForceUpdate=!0,c&&K(t))}}n=J;var Y={setState:X,forceUpdate:function(t,e){X(t,null,e)},runCallbacks:q};function tt(t,e,n){try{return t()}catch(t){n?n(t):et(e,t)}}function et(t,e){for(var n;t;){var r=t._internal;if("function"==typeof t.componentDidCatch){n=t;break}if(!r||!r._parentInstance)break;t=r._parentInstance}if(n){var o=n._internal;if(o)(o._pendingCallbacks||(o._pendingCallbacks=[])).push(function(){return n.componentDidCatch(e)})}else setTimeout(function(){throw e},0)}var nt=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var n=e.prototype;return n.mountComponent=function(t,e,n,r){this.initComponent(t,e,n),this._updateCount=0;var o,i,u=this._currentElement,a=u.type,s=u.ref,c=u.props,l=a.prototype,f=this._processContext(n);try{l&&l.render?o=new a(c,f):"function"==typeof a?o=new Q(a,s):A(a)}catch(t){return et(e,t)}o.props=c,o.context=f,o.refs={},o.updater=Y;var p=((o._internal=this)._instance=o).state;void 0===p&&(o.state=p=null);var d=null,h=function(t){d=t};o.componentWillMount&&tt(function(){o.componentWillMount()},o,h),null==i&&(k.owner=this,o.state=this._processPendingState(c,f),tt(function(){i=o.render()},o,h),k.owner=null),this._renderedComponent=S(i),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(n),r),d&&et(o,d),!u.type.forwardRef&&s&&U.attach(u._owner,s,this),o.componentDidMount&&tt(function(){o.componentDidMount()},o);var v=this._pendingCallbacks;return v&&(this._pendingCallbacks=null,Y.runCallbacks(v,o)),o},n.unmountComponent=function(t){var e=this._instance;if(e&&e.componentWillUnmount&&tt(function(){e.componentWillUnmount()},e),null!=this._renderedComponent){var n=this._currentElement,r=n.ref;!n.type.forwardRef&&r&&U.detach(n._owner,r,this),this._renderedComponent.unmountComponent(t),this._renderedComponent=null}this._pendingStateQueue=null,this._isPendingForceUpdate=!1,this.destoryComponent()},n._processContext=function(t){var e=this._currentElement.type.contextTypes;if(!e)return{};var n={};for(var r in e)n[r]=t[r];return n},n._processChildContext=function(t){var e=this._instance,n=e.getChildContext&&e.getChildContext();return n?Object.assign({},t,n):t},n._processPendingState=function(t,e){var n=this._instance,r=this._pendingStateQueue;if(!r)return n.state;this._pendingStateQueue=null;for(var o=Object.assign({},n.state),i=0;i<r.length;i++){var u=r[i];Object.assign(o,"function"==typeof u?u.call(n,o,t,e):u)}return o},n.updateComponent=function(t,e,n,r){var o=this._instance;o||console.error("Update component '"+this.getName()+"' that has already been unmounted (or failed to mount).");var i,u,a=!1;this._context===r?i=o.context:(i=this._processContext(r),a=!0),t===e?u=e.props:(u=e.props,a=!0),a&&o.componentWillReceiveProps&&(this._isPendingState=!0,tt(function(){o.componentWillReceiveProps(u,i)},o),this._isPendingState=!1),this._currentElement.type.forwardRef?(o.prevForwardRef=t.ref,o.forwardRef=e.ref):U.update(t,e,this);var s=!0,c=o.props,l=o.state,f=this._processPendingState(u,i);if(this._isPendingForceUpdate||(o.shouldComponentUpdate?s=tt(function(){return o.shouldComponentUpdate(u,f,i)},o):o.isPureComponent&&(s=!b(c,u)||!b(l,f))),s){this._isPendingForceUpdate=!1;var p=o.context;tt(function(){o.componentWillUpdate&&o.componentWillUpdate(u,f,i)},o),this._currentElement=e,this._context=r,o.props=u,o.state=f,o.context=i,this._updateRenderedComponent(r),tt(function(){o.componentDidUpdate&&o.componentDidUpdate(c,l,p)},o),this._updateCount++}else this._currentElement=e,this._context=r,o.props=u,o.state=f,o.context=i;var d=this._pendingCallbacks;d&&(this._pendingCallbacks=null,Y.runCallbacks(d,o))},n._updateRenderedComponent=function(t){var e,n=this._renderedComponent,r=n._currentElement,o=this._instance;if(k.owner=this,tt(function(){e=o.render()},o),k.owner=null,D(r,e)){var i=n._context,u=this._processChildContext(t);r===e&&i===u||n.updateComponent(r,e,i,u)}else{var a=n.getNativeNode();n.unmountComponent(!0),this._renderedComponent=S(e),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(t),function(t,e){Array.isArray(t)||(t=[t]),Array.isArray(a)||(a=[a]);for(var n,r=k.driver,o=0;o<t.length;o++){var i=t[o];a[o]?r.replaceChild(i,a[o]):n?r.insertAfter(i,n):r.appendChild(i,e),n=i}if(t.length<a.length)for(var u=t.length;u<a.length;u++)r.removeChild(a[u])})}},n.getNativeNode=function(){var t=this._renderedComponent;if(t)return t.getNativeNode()},n.getPublicInstance=function(){var t=this._instance;return t instanceof Q?null:t},e}(I),rt=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var n=e.prototype;return n.mountComponent=function(t,e,n,r){this.initComponent(t,e,n);var o={_internal:this};this._instance=o;var i=this.getNativeNode(),u=this._currentElement;if(this.mountChildren(u,n),r)r(i,t);else for(var a=0;a<i.length;a++){var s=i[a];k.driver.appendChild(s,t)}return o},n.mountChildren=function(t,e){var n=this.getNativeNode();return this._mountChildren(this._parent,t,e,function(t){Array.isArray(t)||(t=[t]);for(var e=0;e<t.length;e++)n.push(t[e])})},n.unmountComponent=function(t){var e=this._nativeNode;if(e&&(O.remove(e),!t))for(var n=0;n<e.length;n++)k.driver.removeChild(e[n]);this.unmountChildren(!0),this.destoryComponent()},n.updateComponent=function(t,e,n,r){this._currentElement=e,this.updateChildren(this._currentElement,r)},n.createNativeNode=function(){return[]},n.getName=function(){return"fragment"},e}(T);var ot={Host:k,Instance:O,Element:p,flattenChildren:d};t.createElement=c,t.createRef=function(){return{current:null}},t.createContext=function(o){var t,e,i="__context_"+l+++"__",n=function(e){function t(){var t;return(t=e.call(this)||this).emitter=new s(o),t}u(t,e);var n=t.prototype;return n.getChildContext=function(){var t;return(t={})[i]=this.emitter,t},n.componentWillMount=function(){void 0!==this.props.value&&(this.emitter.value=this.props.value)},n.componentWillReceiveProps=function(t){this.props.value!==t.value&&(this.emitter.value=t.value)},n.componentDidUpdate=function(t){this.props.value!==t.value&&this.emitter.emit()},n.render=function(){return this.props.children},t}(a);n.childContextTypes=((t={})[i]=function(){},t),n.contextProp=i,n.defaultValue=o;var r=function(r){function t(t,e){var n;return(n=r.call(this,t,e)||this).state={value:n.readContext(n.context)},n.onUpdate=function(t){return n.state.value!==t&&n.setState({value:t})},n}u(t,r);var e=t.prototype;return e.readContext=function(t){return t[i]?t[i].value:o},e.componentDidMount=function(){this.context[i]&&this.context[i].on(this.onUpdate)},e.componentWillReceiveProps=function(t,e){var n=this.readContext(e);this.state.value!==n&&this.setState({value:n})},e.componentWillUnmount=function(){this.context[i]&&this.context[i].off(this.onUpdate)},e.render=function(){var t=this.props.children,e=Array.isArray(t)?t[0]:t;if("function"==typeof e)return e(this.state.value)},t}(a);return r.contextTypes=((e={})[i]=function(){},e),{Provider:n,Consumer:r}},t.useState=function(t){var n=_(),r=n.getHookID(),o=n.getHooks();o[r]||("function"==typeof t&&(t=t()),o[r]=[t,function(t){var e=o[r][0];"function"==typeof t&&(t=t(e)),t!==e&&(k.owner&&k.owner._instance===n?(o[r][0]=t,n.isScheduled=!0):(!k.isUpdating&&m(),o[r][0]=t,n.update()))}]);return o[r]},t.useContext=function(t){return _().readContext(t)},t.useEffect=function(t,e){g(t,e,!0)},t.useLayoutEffect=C,t.useRef=function(t){var e=_(),n=e.getHookID(),r=e.getHooks();return r[n]||(r[n]={current:t}),r[n]},t.useCallback=function(t,e){return N(function(){return t},e)},t.useMemo=N,t.useReducer=function(t,e,n){var r=_(),o=r.getHookID(),i=r.getHooks();if(!i[o])return n&&(e=t(e,n)),i[o]=[e,function(t){var e=i[o][2];k.owner&&k.owner._instance===r?(e.push(t),r.isScheduled=!0):(!k.isUpdating&&m(),e.push(t),r.update())},[]];for(var u=i[o],a=u[2],s=u[0],c=0;c<a.length;c++)s=t(s,a[c]);return u[0]=s,u[2]=[],i[o]},t.useImperativeHandle=function(t,e,n){C(function(){return"function"==typeof t?(t(e()),function(){return t(null)}):null!=t?(t.current=e(),function(){t.current=null}):void 0},null!=n?n.concat([t]):[t,e])},t.Fragment=function(t){return t.children},t.memo=function(t,e){return void 0===e&&(e=b),t.compares?t.compares.push(e):t.compares=[e],t},t.render=function(t,e,n,r){"function"==typeof n&&(r=n,n=null),function(t){var e=t.driver;if(t.measurer,k.Empty=E,k.Native=T,k.Text=L,k.Fragment=rt,k.Composite=nt,k.driver=e||k.driver,!k.driver)throw Error("Driver not found.")}(n=n||{});var o=O.mount(t,e,n.parent).getPublicInstance();return r&&r.call(o),o},t.version="1.0.0-beta",t.shared=ot,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=rax.min.js.map |
@@ -20,2 +20,4 @@ "use strict"; | ||
var _base = _interopRequireDefault(require("./base")); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
@@ -25,2 +27,4 @@ | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function performInSandbox(fn, instance, callback) { | ||
@@ -88,5 +92,7 @@ try { | ||
/*#__PURE__*/ | ||
function () { | ||
function CompositeComponent(element) { | ||
this._currentElement = element; | ||
function (_BaseComponent) { | ||
_inheritsLoose(CompositeComponent, _BaseComponent); | ||
function CompositeComponent() { | ||
return _BaseComponent.apply(this, arguments) || this; | ||
} | ||
@@ -96,16 +102,6 @@ | ||
_proto.getName = function getName() { | ||
var type = this._currentElement.type; | ||
var instance = this._instance; | ||
var constructor = instance && instance.constructor; | ||
return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || null; | ||
}; | ||
_proto.mountComponent = function mountComponent(parent, parentInstance, context, childMounter) { | ||
_proto.mountComponent = function mountComponent(parent, parentInstance, context, nativeNodeMounter) { | ||
var _this = this; | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
this._mountID = _host.default.mountID++; | ||
this.initComponent(parent, parentInstance, context); | ||
this._updateCount = 0; | ||
@@ -140,4 +136,3 @@ | ||
} catch (e) { | ||
handleError(parentInstance, e); | ||
return instance; | ||
return handleError(parentInstance, e); | ||
} // These should be set up in the constructor, but as a convenience for | ||
@@ -198,3 +193,3 @@ // simpler class abstractions, we set them up after the fact. | ||
this._renderedComponent.mountComponent(this._parent, instance, this._processChildContext(context), childMounter); | ||
this._renderedComponent.mountComponent(this._parent, instance, this._processChildContext(context), nativeNodeMounter); | ||
@@ -239,10 +234,7 @@ if (error) { | ||
_proto.unmountComponent = function unmountComponent(notRemoveChild) { | ||
var instance = this._instance; | ||
_proto.unmountComponent = function unmountComponent(shouldNotRemoveChild) { | ||
var instance = this._instance; // Unmounting a composite component maybe not complete mounted | ||
// when throw error in component constructor stage | ||
if (!instance) { | ||
return; | ||
} | ||
if (instance.componentWillUnmount) { | ||
if (instance && instance.componentWillUnmount) { | ||
performInSandbox(function () { | ||
@@ -253,8 +245,2 @@ instance.componentWillUnmount(); | ||
if (process.env.NODE_ENV !== 'production') { | ||
_host.default.hook.Reconciler.unmountComponent(this); | ||
} | ||
instance._internal = null; | ||
if (this._renderedComponent != null) { | ||
@@ -268,18 +254,13 @@ var currentElement = this._currentElement; | ||
this._renderedComponent.unmountComponent(notRemoveChild); | ||
this._renderedComponent.unmountComponent(shouldNotRemoveChild); | ||
this._renderedComponent = null; | ||
this._instance = null; | ||
} | ||
this._currentElement = null; | ||
this._parentInstance = null; // Reset pending fields | ||
} // Reset pending fields | ||
// Even if this component is scheduled for another async update, | ||
// it would still be ignored because these fields are reset. | ||
this._pendingStateQueue = null; | ||
this._isPendingForceUpdate = false; // These fields do not really need to be reset since this object is no | ||
// longer accessible. | ||
this._context = null; | ||
this._isPendingForceUpdate = false; | ||
this.destoryComponent(); | ||
} | ||
@@ -310,3 +291,4 @@ /** | ||
_proto._processChildContext = function _processChildContext(currentContext) { | ||
var instance = this._instance; | ||
var instance = this._instance; // The getChildContext method context should be current instance | ||
var childContext = instance.getChildContext && instance.getChildContext(); | ||
@@ -565,5 +547,5 @@ | ||
return CompositeComponent; | ||
}(); | ||
}(_base.default); | ||
var _default = CompositeComponent; | ||
exports.default = _default; |
@@ -8,4 +8,8 @@ "use strict"; | ||
var _base = _interopRequireDefault(require("./base")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
/** | ||
@@ -16,5 +20,7 @@ * Empty Component | ||
/*#__PURE__*/ | ||
function () { | ||
function (_BaseComponent) { | ||
_inheritsLoose(EmptyComponent, _BaseComponent); | ||
function EmptyComponent() { | ||
this._currentElement = null; | ||
return _BaseComponent.apply(this, arguments) || this; | ||
} | ||
@@ -24,47 +30,10 @@ | ||
_proto.mountComponent = function mountComponent(parent, parentInstance, context, childMounter) { | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
var instance = { | ||
_internal: this | ||
}; | ||
var nativeNode = this.getNativeNode(); | ||
if (childMounter) { | ||
childMounter(nativeNode, parent); | ||
} else { | ||
_host.default.driver.appendChild(nativeNode, parent); | ||
} | ||
return instance; | ||
_proto.createNativeNode = function createNativeNode() { | ||
return _host.default.driver.createEmpty(); | ||
}; | ||
_proto.unmountComponent = function unmountComponent(notRemoveChild) { | ||
if (this._nativeNode && !notRemoveChild) { | ||
_host.default.driver.removeChild(this._nativeNode, this._parent); | ||
} | ||
this._nativeNode = null; | ||
this._parent = null; | ||
this._parentInstance = null; | ||
this._context = null; | ||
}; | ||
_proto.updateComponent = function updateComponent() {// Noop | ||
}; | ||
_proto.getNativeNode = function getNativeNode() { | ||
// Weex native node | ||
if (this._nativeNode == null) { | ||
this._nativeNode = _host.default.driver.createEmpty(); | ||
} | ||
return this._nativeNode; | ||
}; | ||
return EmptyComponent; | ||
}(); | ||
}(_base.default); | ||
var _default = EmptyComponent; | ||
exports.default = _default; |
@@ -24,4 +24,4 @@ "use strict"; | ||
function FragmentComponent(element) { | ||
return _NativeComponent.call(this, element) || this; | ||
function FragmentComponent() { | ||
return _NativeComponent.apply(this, arguments) || this; | ||
} | ||
@@ -31,8 +31,4 @@ | ||
_proto.mountComponent = function mountComponent(parent, parentInstance, context, childMounter) { | ||
// Parent native element | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
this._mountID = _host.default.mountID++; | ||
_proto.mountComponent = function mountComponent(parent, parentInstance, context, nativeNodeMounter) { | ||
this.initComponent(parent, parentInstance, context); | ||
var instance = { | ||
@@ -47,4 +43,4 @@ _internal: this | ||
if (childMounter) { | ||
childMounter(fragment, parent); | ||
if (nativeNodeMounter) { | ||
nativeNodeMounter(fragment, parent); | ||
} else { | ||
@@ -74,3 +70,3 @@ for (var i = 0; i < fragment.length; i++) { | ||
_proto.unmountComponent = function unmountComponent(notRemoveChild) { | ||
_proto.unmountComponent = function unmountComponent(shouldNotRemoveChild) { | ||
var nativeNode = this._nativeNode; | ||
@@ -81,3 +77,3 @@ | ||
if (!notRemoveChild) { | ||
if (!shouldNotRemoveChild) { | ||
for (var i = 0; i < nativeNode.length; i++) { | ||
@@ -91,8 +87,3 @@ _host.default.driver.removeChild(nativeNode[i]); | ||
this.unmountChildren(true); | ||
this._currentElement = null; | ||
this._nativeNode = null; | ||
this._parent = null; | ||
this._parentInstance = null; | ||
this._context = null; | ||
this._instance = null; | ||
this.destoryComponent(); | ||
}; | ||
@@ -106,14 +97,6 @@ | ||
_proto.getNativeNode = function getNativeNode() { | ||
if (this._nativeNode == null) { | ||
this._nativeNode = []; | ||
} | ||
return this._nativeNode; | ||
_proto.createNativeNode = function createNativeNode() { | ||
return []; | ||
}; | ||
_proto.getPublicInstance = function getPublicInstance() { | ||
return this.getNativeNode(); | ||
}; | ||
_proto.getName = function getName() { | ||
@@ -120,0 +103,0 @@ return 'fragment'; |
@@ -26,3 +26,3 @@ "use strict"; | ||
} else if (typeof element === 'string' || typeof element === 'number') { | ||
instance = new _host.default.Text(element); | ||
instance = new _host.default.Text(String(element)); | ||
} else { | ||
@@ -29,0 +29,0 @@ throwInvalidComponentError(element); |
@@ -18,4 +18,8 @@ "use strict"; | ||
var _base = _interopRequireDefault(require("./base")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
var STYLE = 'style'; | ||
@@ -31,5 +35,7 @@ var CHILDREN = 'children'; | ||
/*#__PURE__*/ | ||
function () { | ||
function NativeComponent(element) { | ||
this._currentElement = element; | ||
function (_BaseComponent) { | ||
_inheritsLoose(NativeComponent, _BaseComponent); | ||
function NativeComponent() { | ||
return _BaseComponent.apply(this, arguments) || this; | ||
} | ||
@@ -39,10 +45,6 @@ | ||
_proto.mountComponent = function mountComponent(parent, parentInstance, context, childMounter) { | ||
_proto.mountComponent = function mountComponent(parent, parentInstance, context, nativeNodeMounter) { | ||
var _this = this; | ||
// Parent native element | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
this._mountID = _host.default.mountID++; | ||
this.initComponent(parent, parentInstance, context); | ||
var currentElement = this._currentElement; | ||
@@ -66,4 +68,4 @@ var props = currentElement.props; | ||
if (childMounter) { | ||
childMounter(nativeNode, parent); | ||
if (nativeNodeMounter) { | ||
nativeNodeMounter(nativeNode, parent); | ||
} else { | ||
@@ -111,3 +113,3 @@ _host.default.driver.appendChild(nativeNode, parent); | ||
_proto._mountChildren = function _mountChildren(parent, children, context, childMounter) { | ||
_proto._mountChildren = function _mountChildren(parent, children, context, nativeNodeMounter) { | ||
var _this2 = this; | ||
@@ -122,3 +124,3 @@ | ||
var mountImage = renderedChild.mountComponent(parent, _this2._instance, context, childMounter); | ||
var mountImage = renderedChild.mountComponent(parent, _this2._instance, context, nativeNodeMounter); | ||
return mountImage; | ||
@@ -129,3 +131,3 @@ }); | ||
_proto.unmountChildren = function unmountChildren(notRemoveChild) { | ||
_proto.unmountChildren = function unmountChildren(shouldNotRemoveChild) { | ||
var renderedChildren = this._renderedChildren; | ||
@@ -136,3 +138,3 @@ | ||
var renderedChild = renderedChildren[name]; | ||
renderedChild.unmountComponent(notRemoveChild); | ||
renderedChild.unmountComponent(shouldNotRemoveChild); | ||
} | ||
@@ -144,3 +146,3 @@ | ||
_proto.unmountComponent = function unmountComponent(notRemoveChild) { | ||
_proto.unmountComponent = function unmountComponent(shouldNotRemoveChild) { | ||
if (this._nativeNode) { | ||
@@ -155,3 +157,3 @@ var ref = this._currentElement.ref; | ||
if (!notRemoveChild) { | ||
if (!shouldNotRemoveChild) { | ||
_host.default.driver.removeChild(this._nativeNode, this._parent); | ||
@@ -161,15 +163,5 @@ } | ||
this.unmountChildren(notRemoveChild); | ||
if (process.env.NODE_ENV !== 'production') { | ||
_host.default.hook.Reconciler.unmountComponent(this); | ||
} | ||
this._currentElement = null; | ||
this._nativeNode = null; | ||
this._parent = null; | ||
this._parentInstance = null; | ||
this._context = null; | ||
this._instance = null; | ||
this.unmountChildren(shouldNotRemoveChild); | ||
this._prevStyleCopy = null; | ||
this.destoryComponent(); | ||
}; | ||
@@ -464,24 +456,14 @@ | ||
_proto.getNativeNode = function getNativeNode() { | ||
if (this._nativeNode == null) { | ||
this._nativeNode = _host.default.driver.createElement(this._instance); | ||
_proto.createNativeNode = function createNativeNode() { | ||
var nativeNode = _host.default.driver.createElement(this._instance); | ||
_instance.default.set(this._nativeNode, this._instance); | ||
} | ||
_instance.default.set(nativeNode, this._instance); | ||
return this._nativeNode; | ||
return nativeNode; | ||
}; | ||
_proto.getPublicInstance = function getPublicInstance() { | ||
return this.getNativeNode(); | ||
}; | ||
_proto.getName = function getName() { | ||
return this._currentElement.type; | ||
}; | ||
return NativeComponent; | ||
}(); | ||
}(_base.default); | ||
var _default = NativeComponent; | ||
exports.default = _default; |
@@ -7,3 +7,2 @@ "use strict"; | ||
function shouldUpdateComponent(prevElement, nextElement) { | ||
// TODO: prevElement and nextElement could be array | ||
var prevEmpty = prevElement === null; | ||
@@ -22,2 +21,3 @@ var nextEmpty = nextElement === null; | ||
} else { | ||
// prevElement and nextElement could be array, typeof [] is "object" | ||
return prevType === 'object' && nextType === 'object' && prevElement.type === nextElement.type && prevElement.key === nextElement.key; | ||
@@ -24,0 +24,0 @@ } |
@@ -8,4 +8,8 @@ "use strict"; | ||
var _base = _interopRequireDefault(require("./base")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
/** | ||
@@ -16,7 +20,7 @@ * Text Component | ||
/*#__PURE__*/ | ||
function () { | ||
function TextComponent(element) { | ||
this._currentElement = element; // Text string | ||
function (_BaseComponent) { | ||
_inheritsLoose(TextComponent, _BaseComponent); | ||
this._text = String(element); | ||
function TextComponent() { | ||
return _BaseComponent.apply(this, arguments) || this; | ||
} | ||
@@ -26,54 +30,11 @@ | ||
_proto.mountComponent = function mountComponent(parent, parentInstance, context, childMounter) { | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
this._mountID = _host.default.mountID++; // Weex dom operation | ||
_proto.updateComponent = function updateComponent(prevElement, nextElement, context) { | ||
nextElement = String(nextElement); // If text is some value that do not update even there number 1 and string "1" | ||
var nativeNode = this.getNativeNode(); | ||
if (childMounter) { | ||
childMounter(nativeNode, parent); | ||
} else { | ||
_host.default.driver.appendChild(nativeNode, parent); | ||
} | ||
var instance = { | ||
_internal: this | ||
}; | ||
if (process.env.NODE_ENV !== 'production') { | ||
_host.default.hook.Reconciler.mountComponent(this); | ||
} | ||
return instance; | ||
}; | ||
_proto.unmountComponent = function unmountComponent(notRemoveChild) { | ||
if (this._nativeNode && !notRemoveChild) { | ||
_host.default.driver.removeChild(this._nativeNode, this._parent); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
_host.default.hook.Reconciler.unmountComponent(this); | ||
} | ||
this._currentElement = null; | ||
this._nativeNode = null; | ||
this._parent = null; | ||
this._parentInstance = null; | ||
this._context = null; | ||
this._text = null; | ||
}; | ||
_proto.updateComponent = function updateComponent(prevElement, nextElement, context) { | ||
// If some text do noting | ||
if (prevElement !== nextElement) { | ||
// Replace current element | ||
this._currentElement = nextElement; // Devtool read the latest stringText value | ||
this._currentElement = nextElement; | ||
this._text = String(nextElement); | ||
_host.default.driver.updateText(this.getNativeNode(), this._currentElement); | ||
_host.default.driver.updateText(this.getNativeNode(), this._text); | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -85,14 +46,10 @@ _host.default.hook.Reconciler.receiveComponent(this); | ||
_proto.getNativeNode = function getNativeNode() { | ||
if (this._nativeNode == null) { | ||
this._nativeNode = _host.default.driver.createText(this._text); | ||
} | ||
return this._nativeNode; | ||
_proto.createNativeNode = function createNativeNode() { | ||
return _host.default.driver.createText(this._currentElement); | ||
}; | ||
return TextComponent; | ||
}(); | ||
}(_base.default); | ||
var _default = TextComponent; | ||
exports.default = _default; |
{ | ||
"name": "rax", | ||
"version": "1.0.0-beta.11", | ||
"version": "1.0.0-beta.12", | ||
"description": "A universal React-compatible render engine.", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -817,2 +817,68 @@ /* @jsx createElement */ | ||
}); | ||
it('should update fragment to right position', function() { | ||
let el = createNodeElement('div'); | ||
class Hello1 extends Component { | ||
render() { | ||
if (this.props.show) { | ||
return 'hello1'; | ||
} | ||
return null; | ||
} | ||
} | ||
class Text extends Component { | ||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
class Hello2 extends Component { | ||
render() { | ||
if (this.props.show) { | ||
return [<Text key="1">1</Text>, <Text key="2">2</Text>, <Text key="3">3</Text>]; | ||
} else { | ||
return [<Text key="1">1</Text>, <Text key="2">2</Text>]; | ||
} | ||
} | ||
} | ||
class MyComponent extends Component { | ||
state = { | ||
show: false | ||
} | ||
render() { | ||
return ( | ||
<div> | ||
{'foo'} | ||
<Hello1 show={this.state.show} /> | ||
<Hello2 show={this.state.show} /> | ||
</div> | ||
); | ||
} | ||
} | ||
let inst = render(<MyComponent />, el); | ||
let container = el.childNodes[0]; | ||
let childNodes = container.childNodes; | ||
expect(childNodes.length).toBe(4); | ||
expect(childNodes[0].data).toBe('foo'); | ||
expect(childNodes[1].data).toBe(' empty '); | ||
expect(childNodes[2].data).toBe('1'); | ||
expect(childNodes[3].data).toBe('2'); | ||
inst.setState({ | ||
show: true | ||
}); | ||
childNodes = container.childNodes; | ||
expect(childNodes.length).toBe(5); | ||
expect(childNodes[0].data).toBe('foo'); | ||
expect(childNodes[1].data).toBe('hello1'); | ||
expect(childNodes[2].data).toBe('1'); | ||
expect(childNodes[3].data).toBe('2'); | ||
expect(childNodes[4].data).toBe('3'); | ||
}); | ||
}); |
@@ -8,2 +8,3 @@ import ReactiveComponent from './reactive'; | ||
import shallowEqual from './shallowEqual'; | ||
import BaseComponent from './base'; | ||
@@ -64,23 +65,5 @@ function performInSandbox(fn, instance, callback) { | ||
*/ | ||
class CompositeComponent { | ||
constructor(element) { | ||
this._currentElement = element; | ||
} | ||
getName() { | ||
let type = this._currentElement.type; | ||
let instance = this._instance; | ||
let constructor = instance && instance.constructor; | ||
return ( | ||
type.displayName || constructor && constructor.displayName || | ||
type.name || constructor && constructor.name || | ||
null | ||
); | ||
} | ||
mountComponent(parent, parentInstance, context, childMounter) { | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
this._mountID = Host.mountID++; | ||
class CompositeComponent extends BaseComponent { | ||
mountComponent(parent, parentInstance, context, nativeNodeMounter) { | ||
this.initComponent(parent, parentInstance, context); | ||
this._updateCount = 0; | ||
@@ -116,4 +99,3 @@ | ||
} catch (e) { | ||
handleError(parentInstance, e); | ||
return instance; | ||
return handleError(parentInstance, e); | ||
} | ||
@@ -179,3 +161,3 @@ | ||
this._processChildContext(context), | ||
childMounter | ||
nativeNodeMounter | ||
); | ||
@@ -218,10 +200,8 @@ | ||
unmountComponent(notRemoveChild) { | ||
unmountComponent(shouldNotRemoveChild) { | ||
let instance = this._instance; | ||
if (!instance) { | ||
return; | ||
} | ||
if (instance.componentWillUnmount) { | ||
// Unmounting a composite component maybe not complete mounted | ||
// when throw error in component constructor stage | ||
if (instance && instance.componentWillUnmount) { | ||
performInSandbox(() => { | ||
@@ -232,11 +212,6 @@ instance.componentWillUnmount(); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Host.hook.Reconciler.unmountComponent(this); | ||
} | ||
instance._internal = null; | ||
if (this._renderedComponent != null) { | ||
let currentElement = this._currentElement; | ||
let ref = currentElement.ref; | ||
if (!currentElement.type.forwardRef && ref) { | ||
@@ -246,10 +221,6 @@ Ref.detach(currentElement._owner, ref, this); | ||
this._renderedComponent.unmountComponent(notRemoveChild); | ||
this._renderedComponent.unmountComponent(shouldNotRemoveChild); | ||
this._renderedComponent = null; | ||
this._instance = null; | ||
} | ||
this._currentElement = null; | ||
this._parentInstance = null; | ||
// Reset pending fields | ||
@@ -261,5 +232,3 @@ // Even if this component is scheduled for another async update, | ||
// These fields do not really need to be reset since this object is no | ||
// longer accessible. | ||
this._context = null; | ||
this.destoryComponent(); | ||
} | ||
@@ -274,5 +243,7 @@ | ||
let contextTypes = Component.contextTypes; | ||
if (!contextTypes) { | ||
return {}; | ||
} | ||
let maskedContext = {}; | ||
@@ -287,6 +258,9 @@ for (let contextName in contextTypes) { | ||
let instance = this._instance; | ||
// The getChildContext method context should be current instance | ||
let childContext = instance.getChildContext && instance.getChildContext(); | ||
if (childContext) { | ||
return Object.assign({}, currentContext, childContext); | ||
} | ||
return currentContext; | ||
@@ -475,2 +449,3 @@ } | ||
const nextRenderedUnmaskedContext = this._processChildContext(context); | ||
if (prevRenderedElement !== nextRenderedElement || prevRenderedUnmaskedContext !== nextRenderedUnmaskedContext) { | ||
@@ -477,0 +452,0 @@ prevRenderedComponent.updateComponent( |
import Host from './host'; | ||
import BaseComponent from './base'; | ||
@@ -6,51 +7,8 @@ /** | ||
*/ | ||
class EmptyComponent { | ||
constructor() { | ||
this._currentElement = null; | ||
class EmptyComponent extends BaseComponent { | ||
createNativeNode() { | ||
return Host.driver.createEmpty(); | ||
} | ||
mountComponent(parent, parentInstance, context, childMounter) { | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
let instance = { | ||
_internal: this | ||
}; | ||
let nativeNode = this.getNativeNode(); | ||
if (childMounter) { | ||
childMounter(nativeNode, parent); | ||
} else { | ||
Host.driver.appendChild(nativeNode, parent); | ||
} | ||
return instance; | ||
} | ||
unmountComponent(notRemoveChild) { | ||
if (this._nativeNode && !notRemoveChild) { | ||
Host.driver.removeChild(this._nativeNode, this._parent); | ||
} | ||
this._nativeNode = null; | ||
this._parent = null; | ||
this._parentInstance = null; | ||
this._context = null; | ||
} | ||
updateComponent() { | ||
// Noop | ||
} | ||
getNativeNode() { | ||
// Weex native node | ||
if (this._nativeNode == null) { | ||
this._nativeNode = Host.driver.createEmpty(); | ||
} | ||
return this._nativeNode; | ||
} | ||
} | ||
export default EmptyComponent; |
@@ -9,13 +9,5 @@ import Host from './host'; | ||
class FragmentComponent extends NativeComponent { | ||
constructor(element) { | ||
super(element); | ||
} | ||
mountComponent(parent, parentInstance, context, nativeNodeMounter) { | ||
this.initComponent(parent, parentInstance, context); | ||
mountComponent(parent, parentInstance, context, childMounter) { | ||
// Parent native element | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
this._mountID = Host.mountID++; | ||
let instance = { | ||
@@ -32,4 +24,4 @@ _internal: this, | ||
if (childMounter) { | ||
childMounter(fragment, parent); | ||
if (nativeNodeMounter) { | ||
nativeNodeMounter(fragment, parent); | ||
} else { | ||
@@ -59,3 +51,3 @@ for (let i = 0; i < fragment.length; i++) { | ||
unmountComponent(notRemoveChild) { | ||
unmountComponent(shouldNotRemoveChild) { | ||
let nativeNode = this._nativeNode; | ||
@@ -66,3 +58,3 @@ | ||
if (!notRemoveChild) { | ||
if (!shouldNotRemoveChild) { | ||
for (let i = 0; i < nativeNode.length; i++) { | ||
@@ -77,8 +69,3 @@ Host.driver.removeChild(nativeNode[i]); | ||
this._currentElement = null; | ||
this._nativeNode = null; | ||
this._parent = null; | ||
this._parentInstance = null; | ||
this._context = null; | ||
this._instance = null; | ||
this.destoryComponent(); | ||
} | ||
@@ -92,14 +79,6 @@ | ||
getNativeNode() { | ||
if (this._nativeNode == null) { | ||
this._nativeNode = []; | ||
} | ||
return this._nativeNode; | ||
createNativeNode() { | ||
return []; | ||
} | ||
getPublicInstance() { | ||
return this.getNativeNode(); | ||
} | ||
getName() { | ||
@@ -106,0 +85,0 @@ return 'fragment'; |
@@ -18,3 +18,3 @@ import Host from './host'; | ||
} else if (typeof element === 'string' || typeof element === 'number') { | ||
instance = new Host.Text(element); | ||
instance = new Host.Text(String(element)); | ||
} else { | ||
@@ -21,0 +21,0 @@ throwInvalidComponentError(element); |
@@ -7,2 +7,3 @@ import Host from './host'; | ||
import Instance from './instance'; | ||
import BaseComponent from './base'; | ||
@@ -17,14 +18,6 @@ const STYLE = 'style'; | ||
*/ | ||
class NativeComponent { | ||
constructor(element) { | ||
this._currentElement = element; | ||
} | ||
class NativeComponent extends BaseComponent { | ||
mountComponent(parent, parentInstance, context, nativeNodeMounter) { | ||
this.initComponent(parent, parentInstance, context); | ||
mountComponent(parent, parentInstance, context, childMounter) { | ||
// Parent native element | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
this._mountID = Host.mountID++; | ||
const currentElement = this._currentElement; | ||
@@ -50,4 +43,4 @@ const props = currentElement.props; | ||
if (childMounter) { | ||
childMounter(nativeNode, parent); | ||
if (nativeNodeMounter) { | ||
nativeNodeMounter(nativeNode, parent); | ||
} else { | ||
@@ -95,3 +88,3 @@ Host.driver.appendChild(nativeNode, parent); | ||
_mountChildren(parent, children, context, childMounter) { | ||
_mountChildren(parent, children, context, nativeNodeMounter) { | ||
let renderedChildren = this._renderedChildren = {}; | ||
@@ -109,3 +102,3 @@ | ||
context, | ||
childMounter | ||
nativeNodeMounter | ||
); | ||
@@ -118,3 +111,3 @@ return mountImage; | ||
unmountChildren(notRemoveChild) { | ||
unmountChildren(shouldNotRemoveChild) { | ||
let renderedChildren = this._renderedChildren; | ||
@@ -125,3 +118,3 @@ | ||
let renderedChild = renderedChildren[name]; | ||
renderedChild.unmountComponent(notRemoveChild); | ||
renderedChild.unmountComponent(shouldNotRemoveChild); | ||
} | ||
@@ -132,3 +125,3 @@ this._renderedChildren = null; | ||
unmountComponent(notRemoveChild) { | ||
unmountComponent(shouldNotRemoveChild) { | ||
if (this._nativeNode) { | ||
@@ -142,3 +135,3 @@ let ref = this._currentElement.ref; | ||
if (!notRemoveChild) { | ||
if (!shouldNotRemoveChild) { | ||
Host.driver.removeChild(this._nativeNode, this._parent); | ||
@@ -148,15 +141,6 @@ } | ||
this.unmountChildren(notRemoveChild); | ||
this.unmountChildren(shouldNotRemoveChild); | ||
if (process.env.NODE_ENV !== 'production') { | ||
Host.hook.Reconciler.unmountComponent(this); | ||
} | ||
this._currentElement = null; | ||
this._nativeNode = null; | ||
this._parent = null; | ||
this._parentInstance = null; | ||
this._context = null; | ||
this._instance = null; | ||
this._prevStyleCopy = null; | ||
this.destoryComponent(); | ||
} | ||
@@ -482,20 +466,9 @@ | ||
getNativeNode() { | ||
if (this._nativeNode == null) { | ||
this._nativeNode = Host.driver.createElement(this._instance); | ||
Instance.set(this._nativeNode, this._instance); | ||
} | ||
return this._nativeNode; | ||
createNativeNode() { | ||
var nativeNode = Host.driver.createElement(this._instance); | ||
Instance.set(nativeNode, this._instance); | ||
return nativeNode; | ||
} | ||
getPublicInstance() { | ||
return this.getNativeNode(); | ||
} | ||
getName() { | ||
return this._currentElement.type; | ||
} | ||
} | ||
export default NativeComponent; |
function shouldUpdateComponent(prevElement, nextElement) { | ||
// TODO: prevElement and nextElement could be array | ||
let prevEmpty = prevElement === null; | ||
@@ -14,2 +13,3 @@ let nextEmpty = nextElement === null; | ||
} else { | ||
// prevElement and nextElement could be array, typeof [] is "object" | ||
return ( | ||
@@ -16,0 +16,0 @@ prevType === 'object' && |
import Host from './host'; | ||
import BaseComponent from './base'; | ||
@@ -6,60 +7,10 @@ /** | ||
*/ | ||
class TextComponent { | ||
constructor(element) { | ||
this._currentElement = element; | ||
// Text string | ||
this._text = String(element); | ||
} | ||
mountComponent(parent, parentInstance, context, childMounter) { | ||
this._parent = parent; | ||
this._parentInstance = parentInstance; | ||
this._context = context; | ||
this._mountID = Host.mountID++; | ||
// Weex dom operation | ||
let nativeNode = this.getNativeNode(); | ||
if (childMounter) { | ||
childMounter(nativeNode, parent); | ||
} else { | ||
Host.driver.appendChild(nativeNode, parent); | ||
} | ||
let instance = { | ||
_internal: this | ||
}; | ||
if (process.env.NODE_ENV !== 'production') { | ||
Host.hook.Reconciler.mountComponent(this); | ||
} | ||
return instance; | ||
} | ||
unmountComponent(notRemoveChild) { | ||
if (this._nativeNode && !notRemoveChild) { | ||
Host.driver.removeChild(this._nativeNode, this._parent); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
Host.hook.Reconciler.unmountComponent(this); | ||
} | ||
this._currentElement = null; | ||
this._nativeNode = null; | ||
this._parent = null; | ||
this._parentInstance = null; | ||
this._context = null; | ||
this._text = null; | ||
} | ||
class TextComponent extends BaseComponent { | ||
updateComponent(prevElement, nextElement, context) { | ||
// If some text do noting | ||
nextElement = String(nextElement); | ||
// If text is some value that do not update even there number 1 and string "1" | ||
if (prevElement !== nextElement) { | ||
// Replace current element | ||
this._currentElement = nextElement; | ||
// Devtool read the latest stringText value | ||
this._text = String(nextElement); | ||
Host.driver.updateText(this.getNativeNode(), this._text); | ||
Host.driver.updateText(this.getNativeNode(), this._currentElement); | ||
@@ -72,7 +23,4 @@ if (process.env.NODE_ENV !== 'production') { | ||
getNativeNode() { | ||
if (this._nativeNode == null) { | ||
this._nativeNode = Host.driver.createText(this._text); | ||
} | ||
return this._nativeNode; | ||
createNativeNode() { | ||
return Host.driver.createText(this._currentElement); | ||
} | ||
@@ -79,0 +27,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115
42
1010559
17867