Comparing version 1.0.0-beta.12 to 1.0.0-beta.13
@@ -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 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})}); | ||
!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 U={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 s(t,e,n){if(null==t)throw Error("createElement: type should not be null or undefined."+function(){var t=U.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=U.owner;if(null!=e)for(r in i=void 0===e.key?null:e.key+"","string"!=typeof(u=void 0===e.ref?null:e.ref)||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=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}(),c=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=U.owner._instance;if(t)return t;throw Error("Hooks can only be called inside a component.")}function C(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 y(t,e){g(t,e)}function g(t,e,o){var n=_(),r=n.getHookID(),i=n.getHooks();if(e=null!=e?e:[t],i[r]){var u=i[r],a=u.create,s=u.inputs;u.inputs=e,u.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=U.isUpdating;U.isUpdating=!0,l.current=n(),t.current=null,U.isUpdating=r}},l=function t(e){if(!e&&o)return v(function(){return t(!0)});var n=t.current;if(n){var r=U.isUpdating;U.isUpdating=!0,n(),t.current=null,U.isUpdating=r}};c.current=t,i[r]={create:c,destory:l,prevInputs:e,inputs:e},n.didMount.push(c),n.willUnmount.push(l),n.didUpdate.push(function(){var t=i[r],e=t.prevInputs,n=t.create;null!=e&&C(t.inputs,e)||(l(),n())})}}function N(t,e){var n=_(),r=n.getHookID(),o=n.getHooks();if(o[r]){var i=o[r];C(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);if(n.length!==Object.keys(e).length)return!1;for(var r=0;r<n.length;r++)if(!x.call(e,n[r])||!w(t[n[r]],e[n[r]]))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=U.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&&U.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):U.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 U.driver.createEmpty()},e}(I),k={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 D(t){var e;return null==t||!1===t||!0===t?e=new U.Empty:Array.isArray(t)?e=new U.Fragment(t):"object"==typeof t&&t.type?e="string"==typeof t.type?new U.Native(t):new U.Composite(t):"string"==typeof t||"number"==typeof t?e=new U.Text(t+""):R(t),e._mountIndex=0,e}function R(t){throw Error("Invalid element type: "+t+". (current: "+("object"==typeof t&&Object.keys(t)||typeof t)+")")}function P(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 S=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},A=1,j=function(e){function t(){var t;return(t=e.call(this)||this).state={element:[]},t.rootID=A++,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&&(U.rootInstances[e.rootID]=e,U.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 U.rootComponents[e.rootID],delete U.rootInstances[e.rootID]))},mount:function(t,e,n){var r,o=U.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=D(s(j)).mountComponent(e,null,r||{});return this.set(e,a),a.update(t),o.afterRender&&o.afterRender(a),a}};function M(t){return Array.isArray(t)||(t=[t]),t}var W="style",F="children",T=/^on[A-Z]/,L=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){var o=this;this.initComponent(t,e,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(){null!=s&&o.mountChildren(s,n)};return"tree"===c?(f(),this.mountNativeNode(r)):(this.mountNativeNode(r),f()),i&&i.ref&&k.attach(i._owner,i.ref,this),l},n.mountChildren=function(t,e){t=M(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=D(t),r=S(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&&k.detach(this._currentElement._owner,e,this),O.remove(this._nativeNode),t||U.driver.removeChild(this._nativeNode,this._parent)}this.unmountChildren(t),this._prevStyleCopy=null,this.destoryComponent()},n.updateComponent=function(t,e,n,r){k.update(t,this._currentElement=e,this);var o=e.props;this.updateProperties(t.props,o),this.updateChildren(o.children,r)},n.updateProperties=function(t,e){var n,r,o,i=U.driver,u=this.getNativeNode();for(n in t)if(n!==F&&null!=t[n]&&!e.hasOwnProperty(n))if(n===W){var a=this._prevStyleCopy;for(r in a)(o=o||{})[r]="";this._prevStyleCopy=null}else if(T.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===W?this._prevStyleCopy:null!=t?t[n]:void 0;if(n!==F&&l!==c&&(null!=c||null!=l))if(n===W)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(T.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=U.driver;if(null!=t||null!=n){var r,u,o,a={};if(null!=t)for(var s=0,c=(t=M(t)).length;s<c;s++){var l=t[s],f=S(a,l,s),p=n&&n[f],d=p&&p._currentElement,h=p&&p._context;a[f]=null!=p&&P(d,l)?(d===l&&h===e||p.updateComponent(d,l,e,e),p):(p&&(p._unmount=!0),D(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 C=function(t,e){if(t=M(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)},y=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!==y&&C(I)}else{var E=this.getNativeNode();Array.isArray(E)&&(E=this._parent),w.mountComponent(E,this._instance,e,C)}w._mountIndex=y++,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 k=0;k<N.length;k++)this._nativeNode.push(N[k])}}o&&r.unmountComponent(),this._renderedChildren=a}},n.createNativeNode=function(){var t=U.driver.createElement(this._instance);return O.set(t,this._instance),t},e}(I),Q=function(t){function e(){return t.apply(this,arguments)||this}u(e,t);var n=e.prototype;return n.updateComponent=function(t,e){t!==(e+="")&&(this._currentElement=e,U.driver.updateText(this.getNativeNode(),this._currentElement))},n.createNativeNode=function(){return U.driver.createText(this._currentElement)},e}(I),B=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;n--)if(e=o[n](r.props,t))break;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;var t=this._render(this.props,this.forwardRef?this.forwardRef:this.context);while(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),V=[];function Z(t){return t._pendingCallbacks}function $(t,e){return t._pendingCallbacks=e}function q(t){return t._pendingStateQueue}function z(t,e){if(t)for(var n=0;n<t.length;n++)t[n].call(e)}function G(t){var e=t._internal;if(e){U.isUpdating=!0;var n=Z(e);$(e,null);var r=e._currentElement,o=e._context,i=e._penddingContext||o;e._penddingContext=void 0,(q(e)||e._isPendingForceUpdate)&&e.updateComponent(r,r,o,i),z(n,t),U.isUpdating=!1}}function J(t,e){return e._internal._mountID-t._internal._mountID}function K(){var t,e;if(!U.isUpdating)while(0<V.length){m(),t=V.sort(J),V=[];while(e=t.pop())G(e)}}function X(t){V.indexOf(t)<0&&V.push(t),K()}function Y(t,e,n){var r=t._internal;if(r){var o,i;!U.isUpdating&&m(),n&&(i=n,(Z(o=r)||$(o,[])).push(i));var u,a,s=r._renderedComponent;e?(a=e,(q(u=r)||(u._pendingStateQueue=[])).push(a),!r._isPendingState&&s&&X(t)):(r._isPendingForceUpdate=!0,s&&X(t))}}n=K;var tt={setState:Y,forceUpdate:function(t,e){Y(t,null,e)},runCallbacks:z};function et(t,e,n){try{return t()}catch(t){n?n(t):nt(e,t)}}function nt(t,e){var n;while(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 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),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 B(a,s):R(a)}catch(t){return nt(e,t)}o.props=c,o.context=f,o.refs={},o.updater=tt;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&&et(function(){o.componentWillMount()},o,h),null==i&&(o.state=(U.owner=this)._processPendingState(c,f),et(function(){i=o.render()},o,h),U.owner=null),this._renderedComponent=D(i),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(n),r),d&&nt(o,d),!u.type.forwardRef&&s&&k.attach(u._owner,s,this),o.componentDidMount&&et(function(){o.componentDidMount()},o);var v=this._pendingCallbacks;return v&&(this._pendingCallbacks=null,tt.runCallbacks(v,o)),o},n.unmountComponent=function(t){var e=this._instance;if(e&&e.componentWillUnmount&&et(function(){e.componentWillUnmount()},e),null!=this._renderedComponent){var n=this._currentElement,r=n.ref;!n.type.forwardRef&&r&&k.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;if(o){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,et(function(){o.componentWillReceiveProps(u,i)},o),this._isPendingState=!1),this._currentElement.type.forwardRef?(o.prevForwardRef=t.ref,o.forwardRef=e.ref):k.update(t,e,this);var s=!0,c=o.props,l=o.state,f=this._processPendingState(u,i);if(this._isPendingForceUpdate||(o.shouldComponentUpdate?s=et(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;et(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),et(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,tt.runCallbacks(d,o))}},n._updateRenderedComponent=function(t){var e,n=this._renderedComponent,r=n._currentElement,o=this._instance;if(U.owner=this,et(function(){e=o.render()},o),U.owner=null,P(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=D(e),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(t),function(t,e){a=M(a),t=M(t);for(var n,r=U.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 B?null:t},e}(I),ot=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,this.mountChildren(this._currentElement,n);var i=this.getNativeNode();if(r)r(i,t);else for(var u=0;u<i.length;u++)U.driver.appendChild(i[u],t);return o},n.mountChildren=function(t,e){var n=this.getNativeNode();return this._mountChildren(this._parent,t,e,function(t){t=M(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++)U.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}(L);var it={Host:U,Instance:O,Element:p,flattenChildren:d};t.createElement=s,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 c(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&&(U.owner&&U.owner._instance===n?(o[r][0]=t,n.isScheduled=!0):(!U.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=y,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];U.owner&&U.owner._instance===r?(e.push(t),r.isScheduled=!0):(!U.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){y(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(U.Empty=E,U.Native=L,U.Text=Q,U.Fragment=ot,U.Composite=rt,U.driver=e||U.driver,!U.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=it,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=rax.min.js.map |
@@ -22,2 +22,4 @@ "use strict"; | ||
var _toArray = _interopRequireDefault(require("./toArray")); | ||
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; } } | ||
@@ -315,4 +317,8 @@ | ||
_proto.updateComponent = function updateComponent(prevElement, nextElement, prevUnmaskedContext, nextUnmaskedContext) { | ||
var instance = this._instance; | ||
var instance = this._instance; // Maybe update component that has already been unmounted or failed mount. | ||
if (!instance) { | ||
return; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -322,6 +328,2 @@ _host.default.measurer && _host.default.measurer.beforeUpdateComponent(this._mountID, this); | ||
if (!instance) { | ||
console.error("Update component '" + this.getName() + "' that has already been unmounted (or failed to mount)."); | ||
} | ||
var willReceive = false; | ||
@@ -478,39 +480,31 @@ var nextContext; | ||
} else { | ||
var oldChild = prevRenderedComponent.getNativeNode(); | ||
var prevNativeNode = prevRenderedComponent.getNativeNode(); | ||
prevRenderedComponent.unmountComponent(true); | ||
this._renderedComponent = (0, _instantiateComponent.default)(nextRenderedElement); | ||
this._renderedComponent.mountComponent(this._parent, instance, this._processChildContext(context), function (newChild, parent) { | ||
// TODO: Duplicate code in native component file | ||
if (!Array.isArray(newChild)) { | ||
newChild = [newChild]; | ||
} // oldChild or newChild all maybe fragment | ||
this._renderedComponent.mountComponent(this._parent, instance, this._processChildContext(context), function (newNativeNode, parent) { | ||
prevNativeNode = (0, _toArray.default)(prevNativeNode); | ||
newNativeNode = (0, _toArray.default)(newNativeNode); | ||
var driver = _host.default.driver; // If the new length large then prev | ||
var lastNativeNode; | ||
if (!Array.isArray(oldChild)) { | ||
oldChild = [oldChild]; | ||
} | ||
for (var i = 0; i < newNativeNode.length; i++) { | ||
var nativeNode = newNativeNode[i]; | ||
var driver = _host.default.driver; // If newChild count large then oldChild | ||
var lastNewChild; | ||
for (var i = 0; i < newChild.length; i++) { | ||
var child = newChild[i]; | ||
if (oldChild[i]) { | ||
driver.replaceChild(child, oldChild[i]); | ||
} else if (lastNewChild) { | ||
driver.insertAfter(child, lastNewChild); | ||
if (prevNativeNode[i]) { | ||
driver.replaceChild(nativeNode, prevNativeNode[i]); | ||
} else if (lastNativeNode) { | ||
driver.insertAfter(nativeNode, lastNativeNode); | ||
} else { | ||
driver.appendChild(child, parent); | ||
driver.appendChild(nativeNode, parent); | ||
} | ||
lastNewChild = child; | ||
} // If newChild count less then oldChild | ||
lastNativeNode = nativeNode; | ||
} // If the new length less then prev | ||
if (newChild.length < oldChild.length) { | ||
for (var _i = newChild.length; _i < oldChild.length; _i++) { | ||
driver.removeChild(oldChild[_i]); | ||
if (newNativeNode.length < prevNativeNode.length) { | ||
for (var _i = newNativeNode.length; _i < prevNativeNode.length; _i++) { | ||
driver.removeChild(prevNativeNode[_i]); | ||
} | ||
@@ -523,2 +517,3 @@ } | ||
_proto.getNativeNode = function getNativeNode() { | ||
// 123 | ||
var renderedComponent = this._renderedComponent; | ||
@@ -525,0 +520,0 @@ |
@@ -12,2 +12,4 @@ "use strict"; | ||
var _toArray = _interopRequireDefault(require("./toArray")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -36,8 +38,7 @@ | ||
}; | ||
this._instance = instance; | ||
this._instance = instance; // Mount children | ||
this.mountChildren(this._currentElement, context); | ||
var fragment = this.getNativeNode(); | ||
var children = this._currentElement; // Process children | ||
this.mountChildren(children, context); | ||
if (nativeNodeMounter) { | ||
@@ -47,5 +48,3 @@ nativeNodeMounter(fragment, parent); | ||
for (var i = 0; i < fragment.length; i++) { | ||
var child = fragment[i]; | ||
_host.default.driver.appendChild(child, parent); | ||
_host.default.driver.appendChild(fragment[i], parent); | ||
} | ||
@@ -60,5 +59,3 @@ } | ||
return this._mountChildren(this._parent, children, context, function (nativeNode) { | ||
if (!Array.isArray(nativeNode)) { | ||
nativeNode = [nativeNode]; | ||
} | ||
nativeNode = (0, _toArray.default)(nativeNode); | ||
@@ -65,0 +62,0 @@ for (var i = 0; i < nativeNode.length; i++) { |
@@ -20,2 +20,4 @@ "use strict"; | ||
var _toArray = _interopRequireDefault(require("./toArray")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -63,12 +65,2 @@ | ||
var mountChild = function mountChild() { | ||
var nativeNode = _this.getNativeNode(); | ||
if (nativeNodeMounter) { | ||
nativeNodeMounter(nativeNode, parent); | ||
} else { | ||
_host.default.driver.appendChild(nativeNode, parent); | ||
} | ||
}; | ||
var mountChildren = function mountChildren() { | ||
@@ -81,8 +73,8 @@ if (children != null) { | ||
if (appendType === TREE) { | ||
// Should after process children when mount child by tree mode | ||
// Should after process children when mount by tree mode | ||
mountChildren(); | ||
mountChild(); | ||
this.mountNativeNode(nativeNodeMounter); | ||
} else { | ||
// Should before process children when mount child by node mode | ||
mountChild(); | ||
// Should before process children when mount by node mode | ||
this.mountNativeNode(nativeNodeMounter); | ||
mountChildren(); | ||
@@ -104,6 +96,3 @@ } // Ref acttach | ||
_proto.mountChildren = function mountChildren(children, context) { | ||
if (!Array.isArray(children)) { | ||
children = [children]; | ||
} | ||
children = (0, _toArray.default)(children); | ||
var nativeNode = this.getNativeNode(); | ||
@@ -308,7 +297,4 @@ return this._mountChildren(nativeNode, children, context); | ||
if (nextChildrenElements != null) { | ||
if (!Array.isArray(nextChildrenElements)) { | ||
nextChildrenElements = [nextChildrenElements]; | ||
} // Update next children elements | ||
nextChildrenElements = (0, _toArray.default)(nextChildrenElements); // Update next children elements | ||
for (var index = 0, length = nextChildrenElements.length; index < length; index++) { | ||
@@ -368,5 +354,3 @@ var nextElement = nextChildrenElements[index]; | ||
// The nativeNodes maybe fragment, so convert to array type | ||
if (!Array.isArray(nativeNodes)) { | ||
nativeNodes = [nativeNodes]; | ||
} | ||
nativeNodes = (0, _toArray.default)(nativeNodes); | ||
@@ -373,0 +357,0 @@ if (lastPlacedNode) { |
{ | ||
"name": "rax", | ||
"version": "1.0.0-beta.12", | ||
"version": "1.0.0-beta.13", | ||
"description": "A universal React-compatible render engine.", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -9,2 +9,3 @@ import ReactiveComponent from './reactive'; | ||
import BaseComponent from './base'; | ||
import toArray from './toArray'; | ||
@@ -290,2 +291,7 @@ function performInSandbox(fn, instance, callback) { | ||
// Maybe update component that has already been unmounted or failed mount. | ||
if (!instance) { | ||
return; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -295,8 +301,2 @@ Host.measurer && Host.measurer.beforeUpdateComponent(this._mountID, this); | ||
if (!instance) { | ||
console.error( | ||
`Update component '${this.getName()}' that has already been unmounted (or failed to mount).` | ||
); | ||
} | ||
let willReceive = false; | ||
@@ -460,3 +460,3 @@ let nextContext; | ||
} else { | ||
let oldChild = prevRenderedComponent.getNativeNode(); | ||
let prevNativeNode = prevRenderedComponent.getNativeNode(); | ||
prevRenderedComponent.unmountComponent(true); | ||
@@ -469,32 +469,26 @@ | ||
this._processChildContext(context), | ||
(newChild, parent) => { | ||
// TODO: Duplicate code in native component file | ||
if (!Array.isArray(newChild)) { | ||
newChild = [newChild]; | ||
} | ||
(newNativeNode, parent) => { | ||
prevNativeNode = toArray(prevNativeNode); | ||
newNativeNode = toArray(newNativeNode); | ||
// oldChild or newChild all maybe fragment | ||
if (!Array.isArray(oldChild)) { | ||
oldChild = [oldChild]; | ||
} | ||
const driver = Host.driver; | ||
const driver = Host.driver; | ||
// If newChild count large then oldChild | ||
let lastNewChild; | ||
for (let i = 0; i < newChild.length; i++) { | ||
let child = newChild[i]; | ||
if (oldChild[i]) { | ||
driver.replaceChild(child, oldChild[i]); | ||
} else if (lastNewChild) { | ||
driver.insertAfter(child, lastNewChild); | ||
// If the new length large then prev | ||
let lastNativeNode; | ||
for (let i = 0; i < newNativeNode.length; i++) { | ||
let nativeNode = newNativeNode[i]; | ||
if (prevNativeNode[i]) { | ||
driver.replaceChild(nativeNode, prevNativeNode[i]); | ||
} else if (lastNativeNode) { | ||
driver.insertAfter(nativeNode, lastNativeNode); | ||
} else { | ||
driver.appendChild(child, parent); | ||
driver.appendChild(nativeNode, parent); | ||
} | ||
lastNewChild = child; | ||
lastNativeNode = nativeNode; | ||
} | ||
// If newChild count less then oldChild | ||
if (newChild.length < oldChild.length) { | ||
for (let i = newChild.length; i < oldChild.length; i++) { | ||
driver.removeChild(oldChild[i]); | ||
// If the new length less then prev | ||
if (newNativeNode.length < prevNativeNode.length) { | ||
for (let i = newNativeNode.length; i < prevNativeNode.length; i++) { | ||
driver.removeChild(prevNativeNode[i]); | ||
} | ||
@@ -508,2 +502,3 @@ } | ||
getNativeNode() { | ||
// 123 | ||
let renderedComponent = this._renderedComponent; | ||
@@ -525,2 +520,2 @@ if (renderedComponent) { | ||
export default CompositeComponent; | ||
export default CompositeComponent; |
import Host from './host'; | ||
import NativeComponent from './native'; | ||
import Instance from './instance'; | ||
import toArray from './toArray'; | ||
@@ -17,8 +18,7 @@ /** | ||
// Mount children | ||
this.mountChildren(this._currentElement, context); | ||
let fragment = this.getNativeNode(); | ||
let children = this._currentElement; | ||
// Process children | ||
this.mountChildren(children, context); | ||
if (nativeNodeMounter) { | ||
@@ -28,4 +28,3 @@ nativeNodeMounter(fragment, parent); | ||
for (let i = 0; i < fragment.length; i++) { | ||
let child = fragment[i]; | ||
Host.driver.appendChild(child, parent); | ||
Host.driver.appendChild(fragment[i], parent); | ||
} | ||
@@ -41,5 +40,3 @@ } | ||
return this._mountChildren(this._parent, children, context, (nativeNode) => { | ||
if (!Array.isArray(nativeNode)) { | ||
nativeNode = [nativeNode]; | ||
} | ||
nativeNode = toArray(nativeNode); | ||
@@ -46,0 +43,0 @@ for (let i = 0; i < nativeNode.length; i++) { |
@@ -8,2 +8,3 @@ import Host from './host'; | ||
import BaseComponent from './base'; | ||
import toArray from './toArray'; | ||
@@ -39,12 +40,2 @@ const STYLE = 'style'; | ||
let mountChild = () => { | ||
let nativeNode = this.getNativeNode(); | ||
if (nativeNodeMounter) { | ||
nativeNodeMounter(nativeNode, parent); | ||
} else { | ||
Host.driver.appendChild(nativeNode, parent); | ||
} | ||
}; | ||
let mountChildren = () => { | ||
@@ -57,8 +48,8 @@ if (children != null) { | ||
if (appendType === TREE) { | ||
// Should after process children when mount child by tree mode | ||
// Should after process children when mount by tree mode | ||
mountChildren(); | ||
mountChild(); | ||
this.mountNativeNode(nativeNodeMounter); | ||
} else { | ||
// Should before process children when mount child by node mode | ||
mountChild(); | ||
// Should before process children when mount by node mode | ||
this.mountNativeNode(nativeNodeMounter); | ||
mountChildren(); | ||
@@ -80,5 +71,3 @@ } | ||
mountChildren(children, context) { | ||
if (!Array.isArray(children)) { | ||
children = [children]; | ||
} | ||
children = toArray(children); | ||
@@ -312,5 +301,3 @@ const nativeNode = this.getNativeNode(); | ||
if (nextChildrenElements != null) { | ||
if (!Array.isArray(nextChildrenElements)) { | ||
nextChildrenElements = [nextChildrenElements]; | ||
} | ||
nextChildrenElements = toArray(nextChildrenElements); | ||
@@ -380,5 +367,3 @@ // Update next children elements | ||
// The nativeNodes maybe fragment, so convert to array type | ||
if (!Array.isArray(nativeNodes)) { | ||
nativeNodes = [nativeNodes]; | ||
} | ||
nativeNodes = toArray(nativeNodes); | ||
@@ -385,0 +370,0 @@ if (lastPlacedNode) { |
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
117
1006565
17806