Comparing version 1.0.4 to 1.0.7
@@ -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 f(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 i=void 0===e.key?null:e.key+"","string"!=typeof(u=void 0===e.ref?null:e.ref)||a||console.error('createElement: adding a string ref "'+u+'" outside the 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}(),e=function(r){function t(t,e){var n;return(n=r.call(this,t,e)||this).isPureComponent=!0,n}return u(t,r),t}(a),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 n=[],r=[],o=setTimeout;function i(t){0===n.length&&o(l),n.push(t)}function l(){var t=n;0!==t.length&&(n=[],t.forEach(function(t){return t()}))}function v(t){0===r.length&&o(m),r.push(t)}function m(){var t=r;0!==t.length&&(r=[],t.forEach(function(t){return t()}))}var _=Object.prototype.hasOwnProperty;function C(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function y(t,e){if(C(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(!_.call(e,n[r])||!C(t[n[r]],e[n[r]]))return!1;return!0}function g(){return k.owner&&k.owner._instance}function N(){var t=g();if(t)return t;throw Error("Hooks can only be called inside a component.")}function x(t,e){if(null===e||t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!C(t[n],e[n]))return!1;return!0}function w(t,e){b(t,e)}function b(t,e,r){var n=N(),o=n.getHookID(),i=n.getHooks();if(e=void 0===e?null:e,i[o]){var u=i[o],a=u.create,s=u.inputs;u.inputs=e,u.prevInputs=s,a.current=t}else{var c=function t(e){if(!e&&r)return v(function(){return t(!0)});var n=t.current;n&&(l.current=n(),t.current=null)},l=function t(e){if(!e&&r)return v(function(){return t(!0)});var n=t.current;n&&(n(),t.current=null)};c.current=t,i[o]={create:c,destory:l,prevInputs:e,inputs:e},n.didMount.push(c),n.willUnmount.push(l),n.didUpdate.push(function(){var t=i[o],e=t.inputs,n=t.create;null!=e&&x(e,t.prevInputs)||(l(),n())})}}function E(t,e){var n=N(),r=n.getHookID(),o=n.getHooks();(e=void 0===e?null:e,o[r])?null!==e&&x(e,o[r][1])||(o[r]=[t(),e]):o[r]=[t(),e];return o[r][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.unmountComponent=function(t){this._nativeNode&&!t&&k.driver.removeChild(this._nativeNode,this._parent),this.destoryComponent()},e.getName=function(){var t=this._currentElement,e=t&&t.type;return e&&e.displayName||e&&e.name||e||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}(),U=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e.prototype.createNativeNode=function(){return k.driver.createEmpty(this)},e}(I),R={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)return console.error("ref: 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 P(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+""):S(t),e}function S(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;if(Array.isArray(t)&&Array.isArray(e))return!0;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 A=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},j=1,H=function(e){function t(){var t;return(t=e.call(this)||this).element=[],t.rootID=j++,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.element=t,this.forceUpdate()},n.render=function(){return this.element},t}(a),W="__r",O={set:function(t,e){t[W]||(t[W]=e).rootID&&(k.rootInstances[e.rootID]=e,k.rootComponents[e.rootID]=e._internal)},get:function(t){return t[W]},remove:function(t){var e=this.get(t);e&&(t[W]=null,e.rootID&&(delete k.rootComponents[e.rootID],delete k.rootInstances[e.rootID]))},mount:function(t,e,n){var r=n.parent,o=n.hydrate,i=k.driver;null==e&&(e=i.createBody());var u,a={element:t,container:e,hydrate:o};if(i.beforeRender&&i.beforeRender(a),r){var s=r._internal;u=s._processChildContext(s._context)}var c=this.get(e);if(c&&c.rootID)return u&&(c._internal._penddingContext=u),c.update(t),c;var l=P(f(H)).mountComponent(e,null,u||{});return this.set(e,l),l.update(t),i.afterRender&&i.afterRender(a),l}};function M(t){return Array.isArray(t)||(t=[t]),t}var F="style",T="children",L=/^on[A-Z]/,Q=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&&R.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=P(t),r=A(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&&R.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){R.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=k.driver,u=this.getNativeNode();for(n in t)if(n!==T&&null!=t[n]&&!e.hasOwnProperty(n))if(n===F){var a=this._prevStyleCopy;for(r in a)(o=o||{})[r]="";this._prevStyleCopy=null}else if(L.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===F?this._prevStyleCopy:null!=t?t[n]:void 0;if(n!==T&&l!==c&&(null!=c||null!=l))if(n===F)if(c?c=this._prevStyleCopy=Object.assign({},c):this._prevStyleCopy=null,null!=l){for(r in l)c&&(c[r]||0===c[r])||((o=o||{})[r]="");for(r in c)l[r]!==c[r]&&((o=o||{})[r]=c[r])}else o=c;else if(L.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.setStyle(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)for(var s=0,c=(t=M(t)).length;s<c;s++){var l=t[s],f=A(a,l,s),p=n&&n[f],d=p&&p._currentElement,h=p&&p._context;a[f]=null!=p&&D(d,l)?(d===l&&h===e||p.updateComponent(d,l,e,e),p):(p&&(p._unmount=!0),P(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 E=b.getNativeNode();b._mountIndex!==y&&C(E)}else{var I=this.getNativeNode();Array.isArray(I)&&(I=this._parent),w.mountComponent(I,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 U=0;U<N.length;U++)this._nativeNode.push(N[U])}}o&&r.unmountComponent(),this._renderedChildren=a}},n.createNativeNode=function(){var t=this._instance,e=k.driver.createElement(t.type,t.props,this);return O.set(e,t),e},e}(I),B=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,k.driver.updateText(this.getNativeNode(),this._currentElement))},n.createNativeNode=function(){return k.driver.createText(this._currentElement,this)},e}(I),V=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,r.shouldUpdate=!1,r._children=null,r.state={},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.componentWillMount=function(){this.shouldUpdate=!0},e.componentDidMount=function(){this.didMount.forEach(function(t){return t()})},e.componentWillReceiveProps=function(){this.shouldUpdate=!0},e.componentDidUpdate=function(){this.didUpdate.forEach(function(t){return t()})},e.componentWillUnmount=function(){this.willUnmount.forEach(function(t){return t()})},e.update=function(){this._internal._isPendingForceUpdate=!0,this.setState({})},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 this.shouldUpdate&&(this._children=t,this.shouldUpdate=!1),this._children},t}(a),Z=[];function $(t){return t._pendingCallbacks}function q(t,e){return t._pendingCallbacks=e}function z(t){return t._pendingStateQueue}function G(t,e){if(t)for(var n=0;n<t.length;n++)t[n].call(e)}function J(t){var e=t._internal;if(e){k.isUpdating=!0;var n=$(e);q(e,null);var r=e._currentElement,o=e._context,i=e._penddingContext||o;e._penddingContext=void 0,(z(e)||e._isPendingForceUpdate)&&e.updateComponent(r,r,o,i),G(n,t),k.isUpdating=!1}}function K(t,e){return e._internal._mountID-t._internal._mountID}function X(){if(k.isUpdating)return i(X);var t,e=Z;if(0<e.length){m(),Z=[],1<e.length&&(e=e.sort(K));while(t=e.pop())J(t)}}function Y(t,e){if(Z.indexOf(t)<0&&Z.push(t),e){if(1<Z.length)return;i(X)}else X()}function tt(t,e,n){var r=t._internal;if(r){var o,i;n&&(i=n,($(o=r)||q(o,[])).push(i));var u,a,s=r._renderedComponent;e?(a=e,(z(u=r)||(u._pendingStateQueue=[])).push(a),!r._isPendingState&&s&&Y(t,!0)):(r._isPendingForceUpdate=!0,s&&Y(t))}}var et={setState:function(t,e,n){k.isUpdating||m(),tt(t,e,n)},forceUpdate:function(t,e){tt(t,null,e)},runCallbacks:G};function nt(t,e,n){try{return t()}catch(t){n?n(t):rt(e,t)}}function rt(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 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),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 V(a,s):S(a)}catch(t){return rt(e,t)}o.props=c,o.context=f,o.refs={},o.updater=et;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&&nt(function(){o.componentWillMount()},o,h),null==i&&(o.state=(k.owner=this)._processPendingState(c,f),nt(function(){i=o.render()},o,h),k.owner=null),this._renderedComponent=P(i),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(n),r),d&&rt(o,d),!u.type.forwardRef&&s&&R.attach(u._owner,s,this),o.componentDidMount&&nt(function(){o.componentDidMount()},o);var v=this._pendingCallbacks;return v&&(this._pendingCallbacks=null,et.runCallbacks(v,o)),o},n.unmountComponent=function(t){var e=this._instance;if(e&&e.componentWillUnmount&&nt(function(){e.componentWillUnmount()},e),null!=this._renderedComponent){var n=this._currentElement,r=n.ref;!n.type.forwardRef&&r&&R.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,nt(function(){o.componentWillReceiveProps(u,i)},o),this._isPendingState=!1),this._currentElement.type.forwardRef?(o.prevForwardRef=t.ref,o.forwardRef=e.ref):R.update(t,e,this);var s=!0,c=o.props,l=o.state,f=this._processPendingState(u,i);if(this._isPendingForceUpdate||(o.shouldComponentUpdate?s=nt(function(){return o.shouldComponentUpdate(u,f,i)},o):o.isPureComponent&&(s=!y(c,u)||!y(l,f))),s){this._isPendingForceUpdate=!1;var p=o.context;nt(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),nt(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,et.runCallbacks(d,o))}},n._updateRenderedComponent=function(t){var e,n=this._renderedComponent,r=n._currentElement,o=this._instance;if(k.owner=this,nt(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=P(e),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(t),function(t,e){a=M(a),t=M(t);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 V?null:t},e}(I),it=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++)k.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++)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[]},e}(Q);var ut={Host:k,Instance:O,Element:p,flattenChildren:d};t.createElement=f,t.createContext=function(o){var t,e,i="__context_"+c+++"__",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.createRef=function(){return{current:null}},t.forwardRef=function(t){return t.forwardRef=!0,t},t.memo=function(t,e){return void 0===e&&(e=y),t.compares?t.compares.push(e):t.compares=[e],t},t.Fragment=function(t){return t.children},t.render=function(t,e,n,r){"function"==typeof n&&(r=n,n=null),function(t){var e=t.driver;if(k.Empty=U,k.Native=Q,k.Text=B,k.Fragment=it,k.Composite=ot,k.driver=e||k.driver,!k.driver)throw Error("Driver not found.")}(n=n||{});var o=O.mount(t,e,n).getPublicInstance();return r&&r.call(o),o},t.Component=a,t.version="1.0.3",t.shared=ut,t.useState=function(t){var r=N(),o=r.getHookID(),i=r.getHooks();i[o]||("function"==typeof t&&(t=t()),i[o]=[t,function(t){k.isUpdating||m();var e=i[o],n=e[2];"function"==typeof t&&(t=t(n)),C(t,n)||(e[2]=t,g()===r?r.isScheduled=!0:r.update())},t]);var e=i[o];return C(e[0],e[2])||(e[0]=e[2],r.shouldUpdate=!0),e},t.useContext=function(t){return N().readContext(t)},t.useEffect=function(t,e){b(t,e,!0)},t.useLayoutEffect=w,t.useRef=function(t){var e=N(),n=e.getHookID(),r=e.getHooks();return r[n]||(r[n]={current:t}),r[n]},t.useCallback=function(t,e){return E(function(){return t},e)},t.useMemo=E,t.useReducer=function(t,e,n){var o=N(),i=o.getHookID(),u=o.getHooks();if(!u[i]){var r=void 0!==n?n(e):e;return u[i]=[r,function(t){k.isUpdating||m();var e=u[i][2];if(g()===o)e.actions.push(t),o.isScheduled=!0;else{var n=e.eagerState,r=(0,e.eagerReducer)(n,t);if(C(r,n))return;e.eagerState=r,e.actions.push(t),o.update()}},{actions:[],eagerReducer:t,eagerState:r}]}var a=u[i],s=a[2],c=a[0];if(0<o._reRenders)for(var l=0;l<s.actions.length;l++)c=t(c,s.actions[l]);else c=s.eagerState;return C(c,a[0])||(a[0]=c,o.shouldUpdate=!0),s.eagerReducer=t,s.eagerState=c,s.actions.length=0,u[i]},t.useImperativeHandle=function(t,e,n){w(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]):null)},t.PureComponent=e,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 h(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 d={key:!0,ref:!0};function f(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 i=void 0===e.key?null:e.key+"","string"!=typeof(u=void 0===e.ref?null:e.ref)||a||console.error('createElement: adding a string ref "'+u+'" outside the render method.'),e)d[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=h(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}(),e=function(r){function t(t,e){var n;return(n=r.call(this,t,e)||this).isPureComponent=!0,n}return u(t,r),t}(a),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 n=[],r=[],o=setTimeout;function i(t){0===n.length&&o(l),n.push(t)}function l(){var t=n;0!==t.length&&(n=[],t.forEach(function(t){return t()}))}function v(t){0===r.length&&o(m),r.push(t)}function m(){var t=r;0!==t.length&&(r=[],t.forEach(function(t){return t()}))}var _=Object.prototype.hasOwnProperty;function C(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function y(t,e){if(C(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(!_.call(e,n[r])||!C(t[n[r]],e[n[r]]))return!1;return!0}function g(){return k.owner&&k.owner._instance}function N(){var t=g();if(t)return t;throw Error("Hooks can only be called inside a component.")}function x(t,e){if(null===e||t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!C(t[n],e[n]))return!1;return!0}function w(t,e){b(t,e)}function b(t,e,r){var n=N(),o=n.getHookID(),i=n.getHooks();if(e=void 0===e?null:e,i[o]){var u=i[o],a=u.create,s=u.inputs;u.inputs=e,u.prevInputs=s,a.current=t}else{var c=function t(e){if(!e&&r)return v(function(){return t(!0)});var n=t.current;n&&(l.current=n(),t.current=null)},l=function t(e){if(!e&&r)return v(function(){return t(!0)});var n=t.current;n&&(n(),t.current=null)};c.current=t,i[o]={create:c,destory:l,prevInputs:e,inputs:e},n.didMount.push(c),n.willUnmount.push(l),n.didUpdate.push(function(){var t=i[o],e=t.inputs,n=t.create;null!=e&&x(e,t.prevInputs)||(l(),n())})}}function E(t,e){var n=N(),r=n.getHookID(),o=n.getHooks();(e=void 0===e?null:e,o[r])?null!==e&&x(e,o[r][1])||(o[r]=[t(),e]):o[r]=[t(),e];return o[r][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.unmountComponent=function(t){this._nativeNode&&!t&&k.driver.removeChild(this._nativeNode,this._parent),this.destoryComponent()},e.getName=function(){var t=this._currentElement,e=t&&t.type;return e&&e.displayName||e&&e.name||e||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}(),U=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e.prototype.createNativeNode=function(){return k.driver.createEmpty(this)},e}(I),R={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)return console.error("ref: 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 P(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+""):S(t),e}function S(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;if(Array.isArray(t)&&Array.isArray(e))return!0;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 A=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},j=1,H=function(e){function t(){var t;return(t=e.call(this)||this).element=[],t.rootID=j++,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.element=t,this.forceUpdate()},n.render=function(){return this.element},t}(a),W="__r",O={set:function(t,e){t[W]||(t[W]=e).rootID&&(k.rootInstances[e.rootID]=e,k.rootComponents[e.rootID]=e._internal)},get:function(t){return t[W]},remove:function(t){var e=this.get(t);e&&(t[W]=null,e.rootID&&(delete k.rootComponents[e.rootID],delete k.rootInstances[e.rootID]))},mount:function(t,e,n){var r=n.parent,o=n.hydrate,i=k.driver;null==e&&(e=i.createBody());var u,a={element:t,container:e,hydrate:o};if(i.beforeRender&&i.beforeRender(a),r){var s=r._internal;u=s._processChildContext(s._context)}var c=this.get(e);if(c&&c.rootID)return u&&(c._internal._penddingContext=u),c.update(t),c;var l=P(f(H)).mountComponent(e,null,u||{});return this.set(e,l),l.update(t),i.afterRender&&i.afterRender(a),l}};function M(t){return Array.isArray(t)||(t=[t]),t}var F="style",T="children",L=/^on[A-Z]/,Q=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&&R.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=P(t),r=A(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&&R.detach(this._currentElement._owner,e,this),O.remove(this._nativeNode),t||(k.driver.removeChild(this._nativeNode,this._parent),t=!0)}this.unmountChildren(t),this._prevStyleCopy=null,this.destoryComponent()},n.updateComponent=function(t,e,n,r){R.update(t,this._currentElement=e,this);var o=t.props,i=e.props;this.updateProperties(o,i),o.children&&0===o.children.length?this.mountChildren(i.children,r):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!==T&&null!=t[n]&&!e.hasOwnProperty(n))if(n===F){var a=this._prevStyleCopy;for(r in a)(o=o||{})[r]="";this._prevStyleCopy=null}else if(L.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===F?this._prevStyleCopy:null!=t?t[n]:void 0;if(n!==T&&l!==c&&(null!=c||null!=l))if(n===F)if(c?c=this._prevStyleCopy=Object.assign({},c):this._prevStyleCopy=null,null!=l){for(r in l)c&&(c[r]||0===c[r])||((o=o||{})[r]="");for(r in c)l[r]!==c[r]&&((o=o||{})[r]=c[r])}else o=c;else if(L.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.setStyle(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)for(var s=0,c=(t=M(t)).length;s<c;s++){var l=t[s],f=A(a,l,s),p=n&&n[f],h=p&&p._currentElement,d=p&&p._context;a[f]=null!=p&&D(h,l)?(h===l&&d===e||p.updateComponent(h,l,e,e),p):(p&&(p._unmount=!0),P(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 E=b.getNativeNode();b._mountIndex!==y&&C(E)}else{var I=this.getNativeNode();Array.isArray(I)&&(I=this._parent),w.mountComponent(I,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 U=0;U<N.length;U++)this._nativeNode.push(N[U])}}o&&r.unmountComponent(),this._renderedChildren=a}},n.createNativeNode=function(){var t=this._instance,e=k.driver.createElement(t.type,t.props,this);return O.set(e,t),e},e}(I),B=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,k.driver.updateText(this.getNativeNode(),this._currentElement))},n.createNativeNode=function(){return k.driver.createText(this._currentElement,this)},e}(I),V=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,r.shouldUpdate=!1,r._children=null,r.state={},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.componentWillMount=function(){this.shouldUpdate=!0},e.componentDidMount=function(){this.didMount.forEach(function(t){return t()})},e.componentWillReceiveProps=function(){this.shouldUpdate=!0},e.componentDidUpdate=function(){this.didUpdate.forEach(function(t){return t()})},e.componentWillUnmount=function(){this.willUnmount.forEach(function(t){return t()})},e.update=function(){this._internal._isPendingForceUpdate=!0,this.setState({})},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 this.shouldUpdate&&(this._children=t,this.shouldUpdate=!1),this._children},t}(a),Z=[];function $(t){return t._pendingCallbacks}function q(t,e){return t._pendingCallbacks=e}function z(t){return t._pendingStateQueue}function G(t,e){if(t)for(var n=0;n<t.length;n++)t[n].call(e)}function J(t){var e=t._internal;if(e){k.isUpdating=!0;var n=$(e);q(e,null);var r=e._currentElement,o=e._context,i=e._penddingContext||o;e._penddingContext=void 0,(z(e)||e._isPendingForceUpdate)&&e.updateComponent(r,r,o,i),G(n,t),k.isUpdating=!1}}function K(t,e){return e._internal._mountID-t._internal._mountID}function X(){if(k.isUpdating)return i(X);var t,e=Z;if(0<e.length){m(),Z=[],1<e.length&&(e=e.sort(K));while(t=e.pop())J(t)}}function Y(t,e){if(Z.indexOf(t)<0&&Z.push(t),e){if(1<Z.length)return;i(X)}else X()}function tt(t,e,n){var r=t._internal;if(r){var o,i;n&&(i=n,($(o=r)||q(o,[])).push(i));var u,a,s=r._renderedComponent;e?(a=e,(z(u=r)||(u._pendingStateQueue=[])).push(a),!r._isPendingState&&s&&Y(t,!0)):(r._isPendingForceUpdate=!0,s&&Y(t))}}var et={setState:function(t,e,n){k.isUpdating||m(),tt(t,e,n)},forceUpdate:function(t,e){tt(t,null,e)},runCallbacks:G};function nt(t,e,n){try{return t()}catch(t){n?n(t):rt(e,t)}}function rt(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 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),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 V(a,s):S(a)}catch(t){return rt(e,t)}o.props=c,o.context=f,o.refs={},o.updater=et;var p=((o._internal=this)._instance=o).state;void 0===p&&(o.state=p=null);var h=null,d=function(t){h=t};o.componentWillMount&&nt(function(){o.componentWillMount()},o,d),null==i&&(o.state=(k.owner=this)._processPendingState(c,f),nt(function(){i=o.render()},o,d),k.owner=null),this._renderedComponent=P(i),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(n),r),h&&rt(o,h),!u.type.forwardRef&&s&&R.attach(u._owner,s,this),o.componentDidMount&&nt(function(){o.componentDidMount()},o);var v=this._pendingCallbacks;return v&&(this._pendingCallbacks=null,et.runCallbacks(v,o)),o},n.unmountComponent=function(t){var e=this._instance;if(e&&e.componentWillUnmount&&nt(function(){e.componentWillUnmount()},e),null!=this._renderedComponent){var n=this._currentElement,r=n.ref;!n.type.forwardRef&&r&&R.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,nt(function(){o.componentWillReceiveProps(u,i)},o),this._isPendingState=!1),this._currentElement.type.forwardRef?(o.prevForwardRef=t.ref,o.forwardRef=e.ref):R.update(t,e,this);var s=!0,c=o.props,l=o.state,f=this._processPendingState(u,i);if(this._isPendingForceUpdate||(o.shouldComponentUpdate?s=nt(function(){return o.shouldComponentUpdate(u,f,i)},o):o.isPureComponent&&(s=!y(c,u)||!y(l,f))),s){this._isPendingForceUpdate=!1;var p=o.context;nt(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),nt(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 h=this._pendingCallbacks;h&&(this._pendingCallbacks=null,et.runCallbacks(h,o))}},n._updateRenderedComponent=function(t){var e,n=this._renderedComponent,r=n._currentElement,o=this._instance;if(k.owner=this,nt(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=P(e),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(t),function(t,e){a=M(a),t=M(t);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 V?null:t},e}(I),it=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++)k.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++)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[]},e}(Q);var ut={Host:k,Instance:O,Element:p,flattenChildren:h};t.createElement=f,t.createContext=function(o){var t,e,i="__context_"+c+++"__",n=function(n){function t(t){var e;return(e=n.call(this,t)||this).emitter=new s(o),e}u(t,n);var e=t.prototype;return e.getChildContext=function(){var t;return(t={})[i]=this.emitter,t},e.componentWillMount=function(){void 0!==this.props.value&&(this.emitter.value=this.props.value)},e.componentWillReceiveProps=function(t){this.props.value!==t.value&&(this.emitter.value=t.value)},e.componentDidUpdate=function(t){this.props.value!==t.value&&this.emitter.emit()},e.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.createRef=function(){return{current:null}},t.forwardRef=function(t){return t.forwardRef=!0,t},t.memo=function(t,e){return void 0===e&&(e=y),t.compares?t.compares.push(e):t.compares=[e],t},t.Fragment=function(t){return t.children},t.render=function(t,e,n,r){"function"==typeof n&&(r=n,n=null),function(t){var e=t.driver;if(k.Empty=U,k.Native=Q,k.Text=B,k.Fragment=it,k.Composite=ot,k.driver=e||k.driver,!k.driver)throw Error("Driver not found.")}(n=n||{});var o=O.mount(t,e,n).getPublicInstance();return r&&r.call(o),o},t.Component=a,t.version="1.0.4",t.shared=ut,t.useState=function(t){var r=N(),o=r.getHookID(),i=r.getHooks();i[o]||("function"==typeof t&&(t=t()),i[o]=[t,function(t){k.isUpdating||m();var e=i[o],n=e[2];"function"==typeof t&&(t=t(n)),C(t,n)||(e[2]=t,g()===r?r.isScheduled=!0:r.update())},t]);var e=i[o];return C(e[0],e[2])||(e[0]=e[2],r.shouldUpdate=!0),e},t.useContext=function(t){return N().readContext(t)},t.useEffect=function(t,e){b(t,e,!0)},t.useLayoutEffect=w,t.useRef=function(t){var e=N(),n=e.getHookID(),r=e.getHooks();return r[n]||(r[n]={current:t}),r[n]},t.useCallback=function(t,e){return E(function(){return t},e)},t.useMemo=E,t.useReducer=function(t,e,n){var o=N(),i=o.getHookID(),u=o.getHooks();if(!u[i]){var r=void 0!==n?n(e):e;return u[i]=[r,function(t){k.isUpdating||m();var e=u[i][2];if(g()===o)e.actions.push(t),o.isScheduled=!0;else{var n=e.eagerState,r=(0,e.eagerReducer)(n,t);if(C(r,n))return;e.eagerState=r,e.actions.push(t),o.update()}},{actions:[],eagerReducer:t,eagerState:r}]}var a=u[i],s=a[2],c=a[0];if(0<o._reRenders)for(var l=0;l<s.actions.length;l++)c=t(c,s.actions[l]);else c=s.eagerState;return C(c,a[0])||(a[0]=c,o.shouldUpdate=!0),s.eagerReducer=t,s.eagerState=c,s.actions.length=0,u[i]},t.useImperativeHandle=function(t,e,n){w(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]):null)},t.PureComponent=e,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=rax.min.js.map |
@@ -10,9 +10,10 @@ "use strict"; | ||
}; | ||
exports.default = void 0; | ||
var _index = require("../index"); | ||
var Rax = _interopRequireWildcard(require("../index")); | ||
Object.keys(_index).forEach(function (key) { | ||
Object.keys(Rax).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
exports[key] = _index[key]; | ||
exports[key] = Rax[key]; | ||
}); | ||
@@ -36,2 +37,11 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
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; } } | ||
Rax.Children = _raxChildren.default; | ||
Rax.isValidElement = _raxIsValidElement.default; | ||
Rax.createFactory = _raxCreateFactory.default; | ||
Rax.cloneElement = _raxCloneElement.default; | ||
var _default = Rax; | ||
exports.default = _default; |
@@ -55,6 +55,6 @@ "use strict"; | ||
function Provider() { | ||
function Provider(props) { | ||
var _this2; | ||
_this2 = _Component.call(this) || this; | ||
_this2 = _Component.call(this, props) || this; | ||
_this2.emitter = new ValueEmitter(defaultValue); | ||
@@ -61,0 +61,0 @@ return _this2; |
import "./jsx"; | ||
export = Rax; | ||
export as namespace Rax; | ||
export declare namespace Rax { | ||
declare namespace Rax { | ||
// | ||
@@ -121,3 +118,3 @@ // Rax Element | ||
// ---------------------------------------------------------------------- | ||
function useContext<T>(context: RaxContext<T>): T; | ||
@@ -132,3 +129,3 @@ | ||
function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, (action: A) => void]; | ||
type MutableRefObject<T> = { readonly current?: T; } | ||
@@ -184,2 +181,2 @@ function useRef<T>(initialValue: T|null): RefObject<T>; | ||
} | ||
} |
@@ -138,3 +138,6 @@ "use strict"; | ||
if (!shouldNotRemoveChild) { | ||
_host.default.driver.removeChild(this._nativeNode, this._parent); | ||
_host.default.driver.removeChild(this._nativeNode, this._parent); // If the parent node has been removed, child node don't need to be removed | ||
shouldNotRemoveChild = true; | ||
} | ||
@@ -156,5 +159,10 @@ } | ||
var nextProps = nextElement.props; | ||
this.updateProperties(prevProps, nextProps); | ||
this.updateChildren(nextProps.children, nextContext); | ||
this.updateProperties(prevProps, nextProps); // If the prevElement has no child, mount children directly | ||
if (prevProps.children && prevProps.children.length === 0) { | ||
this.mountChildren(nextProps.children, nextContext); | ||
} else { | ||
this.updateChildren(nextProps.children, nextContext); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -161,0 +169,0 @@ _host.default.reconciler.receiveComponent(this); |
@@ -5,3 +5,3 @@ "use strict"; | ||
exports.default = void 0; | ||
var _default = '1.0.3'; | ||
var _default = '1.0.4'; | ||
exports.default = _default; |
{ | ||
"name": "rax", | ||
"version": "1.0.4", | ||
"version": "1.0.7", | ||
"description": "A universal React-compatible render engine.", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
@@ -15,3 +15,3 @@ # rax [![npm](https://img.shields.io/npm/v/rax.svg)](https://www.npmjs.com/package/rax) [![Dependency Status](https://david-dm.org/alibaba/rax.svg?path=packages/rax)](https://david-dm.org/alibaba/rax.svg?path=packages/rax) [![Known Vulnerabilities](https://snyk.io/test/npm/rax/badge.svg)](https://snyk.io/test/npm/rax) | ||
import {createElement, render} from 'rax'; | ||
import DriverDOM from 'driver-dom'; | ||
import * as DriverDOM from 'driver-dom'; | ||
@@ -18,0 +18,0 @@ function MyComponent() { |
@@ -0,5 +1,19 @@ | ||
import * as Rax from '../index'; | ||
import Children from 'rax-children'; | ||
import isValidElement from 'rax-is-valid-element'; | ||
import createFactory from 'rax-create-factory'; | ||
import cloneElement from 'rax-clone-element'; | ||
Rax.Children = Children; | ||
Rax.isValidElement = isValidElement; | ||
Rax.createFactory = createFactory; | ||
Rax.cloneElement = cloneElement; | ||
export * from '../index'; | ||
export Children from 'rax-children'; | ||
export isValidElement from 'rax-is-valid-element'; | ||
export createFactory from 'rax-create-factory'; | ||
export cloneElement from 'rax-clone-element'; | ||
export { | ||
Children, | ||
isValidElement, | ||
createFactory, | ||
cloneElement, | ||
}; | ||
export default Rax; |
@@ -28,4 +28,4 @@ import Component from './vdom/component'; | ||
class Provider extends Component { | ||
constructor() { | ||
super(); | ||
constructor(props) { | ||
super(props); | ||
this.emitter = new ValueEmitter(defaultValue); | ||
@@ -32,0 +32,0 @@ } |
import "./jsx"; | ||
export = Rax; | ||
export as namespace Rax; | ||
export declare namespace Rax { | ||
declare namespace Rax { | ||
// | ||
@@ -121,3 +118,3 @@ // Rax Element | ||
// ---------------------------------------------------------------------- | ||
function useContext<T>(context: RaxContext<T>): T; | ||
@@ -132,3 +129,3 @@ | ||
function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, (action: A) => void]; | ||
type MutableRefObject<T> = { readonly current?: T; } | ||
@@ -184,2 +181,2 @@ function useRef<T>(initialValue: T|null): RefObject<T>; | ||
} | ||
} |
@@ -118,2 +118,5 @@ import Host from './host'; | ||
Host.driver.removeChild(this._nativeNode, this._parent); | ||
// If the parent node has been removed, child node don't need to be removed | ||
shouldNotRemoveChild = true; | ||
} | ||
@@ -138,4 +141,10 @@ } | ||
this.updateProperties(prevProps, nextProps); | ||
this.updateChildren(nextProps.children, nextContext); | ||
// If the prevElement has no child, mount children directly | ||
if (prevProps.children && prevProps.children.length === 0) { | ||
this.mountChildren(nextProps.children, nextContext); | ||
} else { | ||
this.updateChildren(nextProps.children, nextContext); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
@@ -142,0 +151,0 @@ Host.reconciler.receiveComponent(this); |
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
920320
119
15839