Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rax

Package Overview
Dependencies
Maintainers
1
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rax - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

lib/compat/index.js

2

dist/rax.min.js

@@ -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 d(t,e,n,r,o){return{type:t,key:e,ref:n,props:r,_owner:o}}function f(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 p(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.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=f(c)}else o.children=n;if(t&&t.defaultProps){var p=t.defaultProps;for(r in p)void 0===o[r]&&(o[r]=p[r])}return new d(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=null,o="undefined"==typeof setImmediate?function(t){return setTimeout(t,0)}:setImmediate,i="undefined"==typeof clearImmediate?clearTimeout:clearImmediate,l=[];function v(){var t=l;l=[],t.forEach(function(t){return t()}),t=null,r()}var m=function(t){0===l.length&&(n=o(v)),l.push(t)};function _(){0!==l.length&&(i(n),v())}var C=Object.prototype.hasOwnProperty;function y(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function g(t,e){if(y(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(!C.call(e,n[r])||!y(t[n[r]],e[n[r]]))return!1;return!0}function N(){return k.owner&&k.owner._instance}function x(){var t=N();if(t)return t;throw Error("Hooks can only be called inside a component.")}function w(t,e){if(null===e||t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!y(t[n],e[n]))return!1;return!0}function b(t,e){U(t,e)}function U(t,e,o){var n=x(),r=n.getHookID(),i=n.getHooks();if(e=void 0===e?null:e,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 m(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 m(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,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.inputs,n=t.create;null!=e&&w(e,t.prevInputs)||(l(),n())})}}function I(t,e){var n=x(),r=n.getHookID(),o=n.getHooks();(e=void 0===e?null:e,o[r])?null!==e&&w(e,o[r][1])||(o[r]=[t(),e]):o[r]=[t(),e];return o[r][0]}var E=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}(),R=function(t){function e(){return t.apply(this,arguments)||this}return u(e,t),e.prototype.createNativeNode=function(){return k.driver.createEmpty(this)},e}(E),S={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 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+""):D(t),e}function D(t){throw Error("Invalid element type: "+t+". (current: "+("object"==typeof t&&Object.keys(t)||typeof t)+")")}function A(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 j=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},H=1,W=function(e){function t(){var t;return(t=e.call(this)||this).state={element:[]},t.rootID=H++,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),M={set:function(t,e){t.__r||(t.__r=e).rootID&&(k.rootInstances[e.rootID]=e,k.rootComponents[e.rootID]=e._internal)},get:function(t){return t.__r},remove:function(t){var e=this.get(t);e&&(t.__r=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(p(W)).mountComponent(e,null,u||{});return this.set(e,l),l.update(t),i.afterRender&&i.afterRender(a),l}};function O(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 p=function(){null!=s&&o.mountChildren(s,n)};return"tree"===c?(p(),this.mountNativeNode(r)):(this.mountNativeNode(r),p()),i&&i.ref&&S.attach(i._owner,i.ref,this),l},n.mountChildren=function(t,e){t=O(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=j(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&&S.detach(this._currentElement._owner,e,this),M.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){S.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]||((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 p=n.slice(2).toLowerCase();"function"==typeof l&&i.removeEventListener(u,p,l,e),"function"==typeof c&&i.addEventListener(u,p,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=O(t)).length;s<c;s++){var l=t[s],p=j(a,l,s),d=n&&n[p],f=d&&d._currentElement,h=d&&d._context;a[p]=null!=d&&A(f,l)?(f===l&&h===e||d.updateComponent(f,l,e,e),d):(d&&(d._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=O(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 U=b.getNativeNode();b._mountIndex!==y&&C(U)}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 E=0;E<N.length;E++)this._nativeNode.push(N[E])}}o&&r.unmountComponent(),this._renderedChildren=a}},n.createNativeNode=function(){var t=this._instance,e=k.driver.createElement(t.type,t.props,this);return M.set(e,t),e},e}(E),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}(E),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,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.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 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(){var t,e;if(!k.isUpdating)while(0<Z.length){_(),t=Z.sort(K),Z=[];while(e=t.pop())J(e)}}function Y(t){Z.indexOf(t)<0&&Z.push(t),X()}function tt(t,e,n){var r=t._internal;if(r){var o,i;!k.isUpdating&&_(),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)):(r._isPendingForceUpdate=!0,s&&Y(t))}}r=X;var et={setState:tt,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,p=this._processContext(n);try{l&&l.render?o=new a(c,p):"function"==typeof a?o=new V(a,s):D(a)}catch(t){return rt(e,t)}o.props=c,o.context=p,o.refs={},o.updater=et;var d=((o._internal=this)._instance=o).state;void 0===d&&(o.state=d=null);var f=null,h=function(t){f=t};o.componentWillMount&&nt(function(){o.componentWillMount()},o,h),null==i&&(o.state=(k.owner=this)._processPendingState(c,p),nt(function(){i=o.render()},o,h),k.owner=null),this._renderedComponent=P(i),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(n),r),f&&rt(o,f),!u.type.forwardRef&&s&&S.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&&S.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):S.update(t,e,this);var s=!0,c=o.props,l=o.state,p=this._processPendingState(u,i);if(this._isPendingForceUpdate||(o.shouldComponentUpdate?s=nt(function(){return o.shouldComponentUpdate(u,p,i)},o):o.isPureComponent&&(s=!g(c,u)||!g(l,p))),s){this._isPendingForceUpdate=!1;var d=o.context;nt(function(){o.componentWillUpdate&&o.componentWillUpdate(u,p,i)},o),this._currentElement=e,this._context=r,o.props=u,o.state=p,o.context=i,this._updateRenderedComponent(r),nt(function(){o.componentDidUpdate&&o.componentDidUpdate(c,l,d)},o),this._updateCount++}else this._currentElement=e,this._context=r,o.props=u,o.state=p,o.context=i;var f=this._pendingCallbacks;f&&(this._pendingCallbacks=null,et.runCallbacks(f,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,A(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=O(a),t=O(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}(E),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=O(t);for(var e=0;e<t.length;e++)n.push(t[e])})},n.unmountComponent=function(t){var e=this._nativeNode;if(e&&(M.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:M,Element:d,flattenChildren:f};t.createElement=p,t.createRef=function(){return{current:null}},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.useState=function(t){var r=x(),o=r.getHookID(),i=r.getHooks();i[o]||("function"==typeof t&&(t=t()),i[o]=[t,function(t){var e=i[o],n=e[2];"function"==typeof t&&(t=t(n)),y(t,n)||(N()===r?(e[2]=t,r.isScheduled=!0):(!k.isUpdating&&_(),e[2]=t,r.update()))},t]);var e=i[o];return y(e[0],e[2])||(e[0]=e[2],r.shouldUpdate=!0),e},t.useContext=function(t){return x().readContext(t)},t.useEffect=function(t,e){U(t,e,!0)},t.useLayoutEffect=b,t.useRef=function(t){var e=x(),n=e.getHookID(),r=e.getHooks();return r[n]||(r[n]={current:t}),r[n]},t.useCallback=function(t,e){return I(function(){return t},e)},t.useMemo=I,t.useReducer=function(t,e,n){var o=x(),i=o.getHookID(),u=o.getHooks();if(!u[i]){var r=void 0!==n?n(e):e;return u[i]=[r,function(t){var e=u[i][2];if(N()===o)e.actions.push(t),o.isScheduled=!0;else{!k.isUpdating&&_();var n=e.eagerState,r=(0,e.eagerReducer)(n,t);if(y(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||s.eagerReducer!=t)for(var l=0;l<s.actions.length;l++)c=t(c,s.actions[l]);else c=s.eagerState;return y(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){b(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.Component=a,t.PureComponent=e,t.Fragment=function(t){return t.children},t.memo=function(t,e){return void 0===e&&(e=g),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(k.Empty=R,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=M.mount(t,e,n).getPublicInstance();return r&&r.call(o),o},t.version="1.0.0-beta",t.shared=ut,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).Rax={})}(this,function(t){"use strict";var k={mountID:1,owner:null,isUpdating:!1,rootComponents:{},rootInstances:{},driver:null};function p(t,e,n,r,o){return{type:t,key:e,ref:n,props:r,_owner:o}}function d(t){if(null==t)return t;var e=[];return function t(e,n){if(Array.isArray(e))for(var r=0,o=e.length;r<o;r++)t(e[r],n);else n.push(e)}(t,e),1===e.length&&(e=e[0]),e}var h={key:!0,ref:!0};function 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 e,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}(),n=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;e="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout;var r=null,o=[],i=[];function l(t){0===o.length&&e(v),o.push(t)}function v(){_();var t=o;0!==t.length&&(o=[],t.forEach(function(t){return t()}),r())}function m(t){0===i.length&&e(_),i.push(t)}function _(){var t=i;0!==t.length&&(i=[],t.forEach(function(t){return t()}))}var C=Object.prototype.hasOwnProperty;function g(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function y(t,e){if(g(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(!C.call(e,n[r])||!g(t[n[r]],e[n[r]]))return!1;return!0}function N(){return k.owner&&k.owner._instance}function x(){var t=N();if(t)return t;throw Error("Hooks can only be called inside a component.")}function w(t,e){if(null===e||t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!g(t[n],e[n]))return!1;return!0}function b(t,e){U(t,e)}function U(t,e,o){var n=x(),r=n.getHookID(),i=n.getHooks();if(e=void 0===e?null:e,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 m(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 m(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,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.inputs,n=t.create;null!=e&&w(e,t.prevInputs)||(l(),n())})}}function E(t,e){var n=x(),r=n.getHookID(),o=n.getHooks();(e=void 0===e?null:e,o[r])?null!==e&&w(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}(),R=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),P={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 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(t+""):D(t),e}function D(t){throw Error("Invalid element type: "+t+". (current: "+("object"==typeof t&&Object.keys(t)||typeof t)+")")}function A(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 j=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},H=1,W=function(e){function t(){var t;return(t=e.call(this)||this).element=[],t.rootID=H++,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),O={set:function(t,e){t.__r||(t.__r=e).rootID&&(k.rootInstances[e.rootID]=e,k.rootComponents[e.rootID]=e._internal)},get:function(t){return t.__r},remove:function(t){var e=this.get(t);e&&(t.__r=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=S(f(W)).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&&P.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=S(t),r=j(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&&P.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){P.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]||((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=j(a,l,s),p=n&&n[f],d=p&&p._currentElement,h=p&&p._context;a[f]=null!=p&&A(d,l)?(d===l&&h===e||p.updateComponent(d,l,e,e),p):(p&&(p._unmount=!0),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 C=function(t,e){if(t=M(t),y)for(var n=t.length-1;0<=n;n--)i.insertAfter(t[n],y);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)},g=0,y=null,N=[];for(var x in a){var w=a[x],b=n&&n[x];if(b===w){var U=b.getNativeNode();b._mountIndex!==g&&C(U)}else{var E=this.getNativeNode();Array.isArray(E)&&(E=this._parent),w.mountComponent(E,this._instance,e,C)}w._mountIndex=g++,y=w.getNativeNode(),N=N.concat(y),Array.isArray(y)&&(y=y[y.length-1])}if(Array.isArray(this._nativeNode)){this._nativeNode.splice(0,this._nativeNode.length);for(var I=0;I<N.length;I++)this._nativeNode.push(N[I])}}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 l(X);var t,e=Z;if(0<e.length){_(),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;l(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))}}r=X;var et={setState:tt,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):D(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=S(i),this._renderedComponent.mountComponent(this._parent,o,this._processChildContext(n),r),d&&rt(o,d),!u.type.forwardRef&&s&&P.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&&P.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):P.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,A(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){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=R,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.0-beta",t.shared=ut,t.useState=function(t){var r=x(),o=r.getHookID(),i=r.getHooks();i[o]||("function"==typeof t&&(t=t()),i[o]=[t,function(t){k.isUpdating||_();var e=i[o],n=e[2];"function"==typeof t&&(t=t(n)),g(t,n)||(e[2]=t,N()===r?r.isScheduled=!0:r.update())},t]);var e=i[o];return g(e[0],e[2])||(e[0]=e[2],r.shouldUpdate=!0),e},t.useContext=function(t){return x().readContext(t)},t.useEffect=function(t,e){U(t,e,!0)},t.useLayoutEffect=b,t.useRef=function(t){var e=x(),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=x(),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||_();var e=u[i][2];if(N()===o)e.actions.push(t),o.isScheduled=!0;else{var n=e.eagerState,r=(0,e.eagerReducer)(n,t);if(g(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||s.eagerReducer!=t)for(var l=0;l<s.actions.length;l++)c=t(c,s.actions[l]);else c=s.eagerState;return g(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){b(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=n,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=rax.min.js.map

@@ -50,3 +50,3 @@ "use strict";

if (typeof ref === 'string' && !ownerComponent) {
console.warn('createElement: adding a string ref outside the component’s render() method.');
console.error('createElement: adding a string ref "' + ref + '" outside the render method.');
} // Remaining properties are added to a new props object

@@ -53,0 +53,0 @@

@@ -65,2 +65,7 @@ "use strict";

var setState = function setState(newState) {
// Flush effects first when not in effect
if (!_host.default.isUpdating) {
(0, _scheduler.flushEffect)();
}
var hook = hooks[hookID];

@@ -76,9 +81,8 @@ var eagerState = hook[2]; // function updater

// After this one render finish, will containue run.
hook[2] = newState;
if (getCurrentInstance() === currentInstance) {
hook[2] = newState; // Marked as is scheduled that could finish hooks.
// Marked as is scheduled that could finish hooks.
currentInstance.isScheduled = true;
} else {
!_host.default.isUpdating && (0, _scheduler.flush)();
hook[2] = newState;
currentInstance.update();

@@ -123,3 +127,3 @@ }

var create = function create(immediately) {
if (!immediately && defered) return (0, _scheduler.schedule)(function () {
if (!immediately && defered) return (0, _scheduler.scheduleEffect)(function () {
return create(true);

@@ -140,3 +144,3 @@ });

var destory = function destory(immediately) {
if (!immediately && defered) return (0, _scheduler.schedule)(function () {
if (!immediately && defered) return (0, _scheduler.scheduleEffect)(function () {
return destory(true);

@@ -251,2 +255,7 @@ });

var dispatch = function dispatch(action) {
// Flush effects first when not in effect
if (!_host.default.isUpdating) {
(0, _scheduler.flushEffect)();
}
var hook = hooks[hookID]; // Reducer will update in the next render, before that we add all

@@ -261,3 +270,2 @@ // actions to the queue

} else {
!_host.default.isUpdating && (0, _scheduler.flush)();
var currentState = queue.eagerState;

@@ -264,0 +272,0 @@ var eagerReducer = queue.eagerReducer;

"use strict";
exports.__esModule = true;
exports.shared = void 0;
exports.shared = exports.PureComponent = exports.useImperativeHandle = exports.useReducer = exports.useMemo = exports.useCallback = exports.useRef = exports.useLayoutEffect = exports.useEffect = exports.useContext = exports.useState = void 0;
var _createElement = _interopRequireDefault(require("./createElement"));
var _createElement2 = _interopRequireDefault(require("./createElement"));
exports.createElement = _createElement.default;
exports.createElement = _createElement2.default;
var _createContext = _interopRequireDefault(require("./createContext"));
var _createContext2 = _interopRequireDefault(require("./createContext"));
exports.createContext = _createContext.default;
exports.createContext = _createContext2.default;
var _createRef = _interopRequireDefault(require("./createRef"));
var _createRef2 = _interopRequireDefault(require("./createRef"));
exports.createRef = _createRef.default;
exports.createRef = _createRef2.default;
var _forwardRef2 = _interopRequireDefault(require("./forwardRef"));
exports.forwardRef = _forwardRef2.default;
var _hooks = require("./hooks");

@@ -30,5 +34,5 @@

var _memo = _interopRequireDefault(require("./memo"));
var _memo2 = _interopRequireDefault(require("./memo"));
exports.memo = _memo.default;
exports.memo = _memo2.default;

@@ -39,5 +43,5 @@ var _fragment = _interopRequireDefault(require("./fragment"));

var _render = _interopRequireDefault(require("./render"));
var _render2 = _interopRequireDefault(require("./render"));
exports.render = _render.default;
exports.render = _render2.default;

@@ -49,5 +53,5 @@ var _component = _interopRequireWildcard(require("./vdom/component"));

var _version = _interopRequireDefault(require("./version"));
var _version2 = _interopRequireDefault(require("./version"));
exports.version = _version.default;
exports.version = _version2.default;

@@ -54,0 +58,0 @@ var _host = _interopRequireDefault(require("./vdom/host"));

@@ -42,2 +42,3 @@ "use strict";

_this._children = null;
_this.state = {};

@@ -59,4 +60,2 @@ if (pureRender.forwardRef) {

}
;
}

@@ -142,3 +141,4 @@

_proto.update = function update() {
this.forceUpdate();
this._internal._isPendingForceUpdate = true;
this.setState({});
};

@@ -145,0 +145,0 @@

@@ -23,3 +23,3 @@ "use strict";

if (!ownerComponent) {
throw Error('Multiple version of Rax used in project.');
return console.error('ref: multiple version of Rax used in project.');
}

@@ -29,2 +29,8 @@

if (process.env.NODE_ENV !== 'production') {
if (instance == null) {
console.error('ref: do not attach ref to function components because they don’t have instances.');
}
}
if (typeof ref === 'function') {

@@ -31,0 +37,0 @@ ref(instance);

@@ -22,7 +22,5 @@ "use strict";

_this = _Component.call(this) || this;
_this.state = {
// Using fragment instead of null for avoid create a comment node when init mount
element: []
};
_this = _Component.call(this) || this; // Using fragment instead of null for avoid create a comment node when init mount
_this.element = [];
_this.rootID = rootID++;

@@ -43,9 +41,8 @@ return _this;

_proto.update = function update(element) {
this.setState({
element: element
});
this.element = element;
this.forceUpdate();
};
_proto.render = function render() {
return this.state.element;
return this.element;
};

@@ -52,0 +49,0 @@

"use strict";
exports.__esModule = true;
exports.schedule = schedule;
exports.flush = flush;
exports.scheduleEffect = scheduleEffect;
exports.flushEffect = flushEffect;
exports.setUpdater = setUpdater;
exports.schedule = void 0;
var scheduler;
if (process.env.NODE_ENV !== 'production') {
scheduler = function scheduler(callback) {
setTimeout(callback);
};
} else {
scheduler = typeof Promise == 'function' ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout;
}
var performUpdate = null;
var updateCallbacks = [];
var effectCallbacks = []; // Schedule before next render
var setImmediatePolyfill = function setImmediatePolyfill(job) {
return setTimeout(job, 0);
}; // 0s
function schedule(callback) {
if (updateCallbacks.length === 0) {
scheduler(flush);
}
updateCallbacks.push(callback);
} // Flush before next render
var scheduleImmediateCallback = typeof setImmediate === 'undefined' ? setImmediatePolyfill : setImmediate;
var cancelImmediateCallback = typeof clearImmediate === 'undefined' ? clearTimeout : clearImmediate;
var beforeNextRenderCallbacks = [];
var beforeNextRenderCallbackId; // Commit before next render
function commit() {
var preCallbacks = beforeNextRenderCallbacks;
beforeNextRenderCallbacks = [];
preCallbacks.forEach(function (callback) {
return callback();
});
preCallbacks = null; // Exec callback maybe schedule a work
function flush() {
flushEffect();
var callbacks = updateCallbacks;
performUpdate();
} // Schedule before next render
if (callbacks.length !== 0) {
updateCallbacks = [];
callbacks.forEach(function (callback) {
return callback();
}); // Exec callback maybe schedule a work
performUpdate();
}
}
var schedule = function schedule(callback) {
if (beforeNextRenderCallbacks.length === 0) {
beforeNextRenderCallbackId = scheduleImmediateCallback(commit);
function scheduleEffect(callback) {
if (effectCallbacks.length === 0) {
scheduler(flushEffect);
}
beforeNextRenderCallbacks.push(callback);
}; // Flush before next render
effectCallbacks.push(callback);
}
function flushEffect() {
var callbacks = effectCallbacks;
exports.schedule = schedule;
function flush() {
if (beforeNextRenderCallbacks.length !== 0) {
cancelImmediateCallback(beforeNextRenderCallbackId);
commit();
if (callbacks.length !== 0) {
effectCallbacks = [];
callbacks.forEach(function (callback) {
return callback();
});
}

@@ -47,0 +63,0 @@ }

@@ -81,19 +81,19 @@ "use strict";

if (_host.default.isUpdating) {
return;
return (0, _scheduler.schedule)(performUpdate);
}
var dirties;
var component;
var dirties = dirtyComponents;
while (dirtyComponents.length > 0) {
// Before next render, we will flush all the PassiveEffects
(0, _scheduler.flush)(); // Since reconciling a component higher in the owner hierarchy usually (not
if (dirties.length > 0) {
// Before next render, we will flush all the effects
(0, _scheduler.flushEffect)();
dirtyComponents = []; // Since reconciling a component higher in the owner hierarchy usually (not
// always -- see shouldComponentUpdate()) will reconcile children, reconcile
// them before their children by sorting the array.
dirties = dirtyComponents.sort(mountOrderComparator); // Reset dirtyComponents, using to collect dirtyComponent
// generated by the next render
if (dirties.length > 1) {
dirties = dirties.sort(mountOrderComparator);
}
dirtyComponents = [];
while (component = dirties.pop()) {

@@ -105,3 +105,3 @@ runUpdate(component);

function scheduleUpdate(component) {
function scheduleUpdate(component, shouldAsyncUpdate) {
if (dirtyComponents.indexOf(component) < 0) {

@@ -111,3 +111,12 @@ dirtyComponents.push(component);

performUpdate();
if (shouldAsyncUpdate) {
// If have been scheduled before, don't not need schedule again
if (dirtyComponents.length > 1) {
return;
}
(0, _scheduler.schedule)(performUpdate);
} else {
performUpdate();
}
}

@@ -122,4 +131,2 @@

!_host.default.isUpdating && (0, _scheduler.flush)();
if (callback) {

@@ -137,3 +144,3 @@ enqueueCallback(internal, callback);

if (!internal._isPendingState && hasComponentRendered) {
scheduleUpdate(component);
scheduleUpdate(component, true);
}

@@ -140,0 +147,0 @@ } else {

{
"name": "rax",
"version": "1.0.0",
"version": "1.0.1",
"description": "A universal React-compatible render engine.",

@@ -20,3 +20,7 @@ "license": "BSD-3-Clause",

"driver-server": "^1.0.0",
"@babel/runtime": "^7.2.0"
"@babel/runtime": "^7.2.0",
"rax-is-valid-element": "^1.0.0",
"rax-clone-element": "^1.0.0",
"rax-children": "^1.0.0",
"rax-create-factory": "^1.0.0"
},

@@ -23,0 +27,0 @@ "devDependencies": {

@@ -24,2 +24,3 @@ /* @jsx createElement */

Host.driver = ServerDriver;
jest.useFakeTimers();
});

@@ -29,2 +30,3 @@

Host.driver = null;
jest.useRealTimers();
});

@@ -117,2 +119,3 @@

render(<App value={3} />, container);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('3');

@@ -123,2 +126,3 @@ expect(container.childNodes[1].childNodes[0].data).toEqual('6');

render(<App value={4} />, container);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('4');

@@ -174,2 +178,3 @@ expect(container.childNodes[1].childNodes[0].data).toEqual('8');

render(<App value={3} />, container);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].childNodes[0].data).toEqual('3');

@@ -210,2 +215,3 @@ expect(container.childNodes[0].childNodes[1].childNodes[0].data).toEqual('3');

render(<App value={3} />, container);
jest.runAllTimers();
expect(spyConsumerRender).toHaveBeenCalledTimes(1);

@@ -212,0 +218,0 @@ expect(spyConsumerWithIndirection).toHaveBeenCalledTimes(1);

@@ -9,3 +9,2 @@ /* @jsx createElement */

import {useState, useContext, useEffect, useLayoutEffect, useRef, useReducer, useImperativeHandle, useMemo} from '../hooks';
import { flush as flushPassiveEffects } from '../vdom/scheduler';
import forwardRef from '../forwardRef';

@@ -67,2 +66,3 @@ import createRef from '../createRef';

stateUpdater(10);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('10');

@@ -84,7 +84,7 @@ });

updaters[0](1);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('1');
updaters[0](count => count + 10);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('11');

@@ -160,3 +160,3 @@

render(<Counter count={0} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -167,3 +167,3 @@ 'render', 'create2', 'create1'

render(<Counter count={1} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -174,3 +174,3 @@ 'render', 'create2', 'create1',

render(<Counter count={2} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -203,3 +203,3 @@ 'render', 'create2', 'create1',

render(<Counter count={0} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(effectCounter).toEqual(1);

@@ -210,3 +210,3 @@ expect(renderCounter).toEqual(1);

render(<Counter count={1} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(renderCounter).toEqual(2);

@@ -217,3 +217,3 @@ expect(effectCounter).toEqual(2);

render(<Counter count={2} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(renderCounter).toEqual(3);

@@ -248,2 +248,3 @@ expect(effectCounter).toEqual(3);

render(<Counter count={0} />, container);
jest.runAllTimers();
expect(effectCounter).toEqual(1);

@@ -254,2 +255,3 @@ expect(renderCounter).toEqual(2);

render(<Counter count={0} />, container);
jest.runAllTimers();
expect(effectCounter).toEqual(1);

@@ -260,2 +262,3 @@ expect(renderCounter).toEqual(3);

render(<Counter count={1} />, container);
jest.runAllTimers();
expect(effectCounter).toEqual(2);

@@ -290,3 +293,3 @@ expect(renderCounter).toEqual(4);

render(<Counter count={0} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(effectCounter).toEqual(1);

@@ -297,3 +300,3 @@ expect(renderCounter).toEqual(2);

render(<Counter count={0} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(effectCounter).toEqual(1);

@@ -304,3 +307,3 @@ expect(renderCounter).toEqual(3);

render(<Counter count={1} />, container);
flushPassiveEffects();
jest.runAllTimers();
expect(effectCounter).toEqual(2);

@@ -335,2 +338,3 @@ expect(renderCounter).toEqual(4);

render(<Counter />, container);
jest.runAllTimers();
expect(effectCounter).toEqual(2);

@@ -365,2 +369,3 @@ expect(renderCounter).toEqual(2);

render(<Counter />, container);
jest.runAllTimers();
expect(effectCounter).toEqual(1);

@@ -425,3 +430,3 @@ expect(renderCounter).toEqual(2);

const logs = [];
logs.yield = logs.push;
logs.flush = function() {

@@ -433,10 +438,4 @@ const result = [...logs];

let batchUpdate = function() {};
function act(callback) {
batchUpdate = callback;
flushPassiveEffects();
}
function Child({text}) {
logs.yield('Child: ' + text);
logs.push('Child: ' + text);
return text;

@@ -454,9 +453,7 @@ }

const text = `${counter1}, ${counter2}`;
logs.yield(`Parent: ${text}`);
logs.push(`Parent: ${text}`);
useLayoutEffect(() => {
logs.yield(`Effect: ${text}`);
logs.push(`Effect: ${text}`);
});
useEffect(() => {
batchUpdate();
});
return <Child text={text} />;

@@ -474,6 +471,5 @@ }

// Normal update
act(() => {
setCounter1(1);
setCounter2(1);
});
setCounter1(1);
setCounter2(1);
jest.runAllTimers();

@@ -488,7 +484,7 @@ expect(logs.flush()).toEqual([

// can't bail out.
act(() => {
setCounter1(1);
setCounter2(2);
});
setCounter1(1);
setCounter2(2);
jest.runAllTimers();
expect(logs.flush()).toEqual([

@@ -501,11 +497,11 @@ 'Parent: 1, 2',

// Lots of updates that eventually resolve to the current values.
act(() => {
setCounter1(9);
setCounter2(3);
setCounter1(4);
setCounter2(7);
setCounter1(1);
setCounter2(2);
});
setCounter1(9);
setCounter2(3);
setCounter1(4);
setCounter2(7);
setCounter1(1);
setCounter2(2);
jest.runAllTimers();
// Because the final values are the same as the current values, the

@@ -516,6 +512,7 @@ // component bails out.

// prepare to check SameValue
act(() => {
setCounter1(0 / -1);
setCounter2(NaN);
});
setCounter1(0 / -1);
setCounter2(NaN);
jest.runAllTimers();
expect(logs.flush()).toEqual([

@@ -528,15 +525,16 @@ 'Parent: 0, NaN',

// check if re-setting to negative 0 / NaN still bails out
act(() => {
setCounter1(0 / -1);
setCounter2(NaN);
setCounter2(Infinity);
setCounter2(NaN);
});
setCounter1(0 / -1);
setCounter2(NaN);
setCounter2(Infinity);
setCounter2(NaN);
jest.runAllTimers();
expect(logs.flush()).toEqual(['Parent: 0, NaN', 'Effect: 0, NaN']);
// check if changing negative 0 to positive 0 does not bail out
act(() => {
setCounter1(0);
});
setCounter1(0);
jest.runAllTimers();
expect(logs.flush()).toEqual([

@@ -552,3 +550,2 @@ 'Parent: 0, NaN',

const logs = [];
logs.yield = logs.push;
logs.flush = function() {

@@ -560,10 +557,4 @@ const result = [...logs];

let batchUpdate = function() {};
function act(callback) {
batchUpdate = callback;
flushPassiveEffects();
}
function Child({text}) {
logs.yield('Child: ' + text);
logs.push('Child: ' + text);
return text;

@@ -574,2 +565,3 @@ }

let setCounter2;
function Parent({theme}) {

@@ -582,6 +574,4 @@ const [counter1, _setCounter1] = useState(0);

const text = `${counter1}, ${counter2} (${theme})`;
logs.yield(`Parent: ${text}`);
useEffect(() => {
batchUpdate();
});
logs.push(`Parent: ${text}`);
return <Child text={text} />;

@@ -592,3 +582,3 @@ }

const root = render(<Parent theme="light" />, container);
render(<Parent theme="light" />, container);
expect(logs.flush()).toEqual([

@@ -600,8 +590,6 @@ 'Parent: 0, 0 (light)',

// Normal update
act(() => {
setCounter1(1);
setCounter2(1);
});
setCounter1(1);
setCounter2(1);
jest.runAllTimers();
expect(logs.flush()).toEqual([

@@ -614,7 +602,6 @@ 'Parent: 1, 1 (light)',

// can't bail out.
act(() => {
setCounter1(1);
setCounter2(2);
});
setCounter1(1);
setCounter2(2);
jest.runAllTimers();
expect(logs.flush()).toEqual([

@@ -627,17 +614,13 @@ 'Parent: 1, 2 (light)',

// have changed
act(() => {
setCounter1(1);
setCounter2(2);
render(<Parent theme="dark" />, container);
});
setCounter1(1);
setCounter2(2);
render(<Parent theme="dark" />, container);
jest.runAllTimers();
expect(logs.flush()).toEqual(['Parent: 1, 2 (dark)', 'Child: 1, 2 (dark)']);
// Both props and state bail out
act(() => {
setCounter1(1);
setCounter2(2);
render(<Parent theme="dark" />, container);
});
setCounter1(1);
setCounter2(2);
render(<Parent theme="dark" />, container);
jest.runAllTimers();
expect(logs.flush()).toEqual([]);

@@ -649,3 +632,3 @@ });

const logs = [];
logs.yield = logs.push;
logs.flush = function() {

@@ -657,8 +640,2 @@ const result = [...logs];

let batchUpdate = function() {};
function act(callback) {
batchUpdate = callback;
flushPassiveEffects();
}
const ThemeContext = createContext('light');

@@ -669,3 +646,3 @@

const [theme, _setTheme] = useState('light');
logs.yield('Theme: ' + theme);
logs.push('Theme: ' + theme);
setTheme = _setTheme;

@@ -678,3 +655,3 @@ return (

function Child({text}) {
logs.yield('Child: ' + text);
logs.push('Child: ' + text);
return text;

@@ -691,9 +668,6 @@ }

const text = `${counter} (${theme})`;
logs.yield(`Parent: ${text}`);
logs.push(`Parent: ${text}`);
useLayoutEffect(() => {
logs.yield(`Effect: ${text}`);
logs.push(`Effect: ${text}`);
});
useEffect(() => {
batchUpdate();
});
return <Child text={text} />;

@@ -724,2 +698,3 @@ }

setCounter(1);
jest.runAllTimers();
expect(logs.flush()).toEqual([

@@ -734,7 +709,7 @@ 'Parent: 1 (light)',

// can't bail out
act(() => {
setCounter(1);
setTheme('dark');
});
setCounter(1);
setTheme('dark');
jest.runAllTimers();
expect(logs.flush()).toEqual([

@@ -903,2 +878,3 @@ 'Theme: dark',

counter.current.dispatch('reset');
jest.runAllTimers();
expect(logs).toEqual([

@@ -943,2 +919,3 @@ 'Render: 0',

counter.current.dispatch(INCREMENT);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('1');

@@ -949,2 +926,3 @@

counter.current.dispatch(DECREMENT);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('-2');

@@ -960,2 +938,3 @@

counter.current.dispatch(INCREMENT);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('-2');

@@ -967,3 +946,3 @@ });

const logs = [];
logs.yield = logs.push;
logs.flush = function() {

@@ -980,5 +959,5 @@ const result = [...logs];

switch (action) {
case 'INCREMENT':
case INCREMENT:
return state + 1;
case 'DECREMENT':
case DECREMENT:
return state - 1;

@@ -997,3 +976,3 @@ default:

const [count, dispatch] = useReducer(reducer, props, p => {
logs.yield('Init');
logs.push('Init');
return p.initialCount;

@@ -1011,2 +990,3 @@ });

counter.current.dispatch(INCREMENT);
jest.runAllTimers();
expect(logs.flush()).toEqual(['Count: 11']);

@@ -1018,4 +998,4 @@ expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 11');

counter.current.dispatch(DECREMENT);
expect(logs.flush()).toEqual(['Count: 10', 'Count: 9', 'Count: 8']);
jest.runAllTimers();
expect(logs.flush()).toEqual(['Count: 8']);
expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 8');

@@ -1027,3 +1007,3 @@ });

const logs = [];
logs.yield = logs.push;
logs.flush = function() {

@@ -1036,3 +1016,3 @@ const result = [...logs];

function Child({text}) {
logs.yield('Child: ' + text);
logs.push('Child: ' + text);
return text;

@@ -1045,8 +1025,2 @@ }

let batchUpdate = function() {};
function act(callback) {
batchUpdate = callback;
flushPassiveEffects();
}
let setCounter1;

@@ -1061,9 +1035,6 @@ let setCounter2;

const text = `${counter1}, ${counter2}`;
logs.yield(`Parent: ${text}`);
logs.push(`Parent: ${text}`);
useLayoutEffect(() => {
logs.yield(`Effect: ${text}`);
logs.push(`Effect: ${text}`);
});
useEffect(() => {
batchUpdate();
});
return <Child text={text} />;

@@ -1081,12 +1052,11 @@ }

// Normal update
act(() => {
setCounter1(1);
setCounter1(2);
setCounter1(2);
setCounter1(3);
setCounter2(2);
setCounter1(3);
setCounter1(3);
setCounter2(4);
});
setCounter1(1);
setCounter1(2);
setCounter1(2);
setCounter1(3);
setCounter2(2);
setCounter1(3);
setCounter1(3);
setCounter2(4);
jest.runAllTimers();

@@ -1099,7 +1069,7 @@ expect(logs.flush()).toEqual([

act(() => {
setCounter1(2);
setCounter2(2);
});
setCounter1(2);
setCounter2(2);
jest.runAllTimers();
expect(logs.flush()).toEqual([

@@ -1111,6 +1081,5 @@ 'Parent: 2, 2',

act(() => {
setCounter1(2);
setCounter2(2);
});
setCounter1(2);
setCounter2(2);
jest.runAllTimers();

@@ -1133,3 +1102,3 @@ expect(logs.flush()).toEqual([]);

expect(container.childNodes[0].childNodes[0].data).toEqual('0');
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did commit [0]']);

@@ -1141,3 +1110,3 @@

// Effects are deferred until after the commit
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did commit [1]']);

@@ -1174,2 +1143,3 @@ });

render([passive], container);
jest.runAllTimers();
expect(logs).toEqual(['Passive effect']);

@@ -1180,3 +1150,3 @@ expect(container.childNodes[0].childNodes[0].data).toEqual('Passive');

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([]);

@@ -1208,3 +1178,3 @@ });

render([<PassiveEffect key="p" />, <LayoutEffect key="l" />], container);
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -1245,2 +1215,3 @@ 'Passive',

render([<PassiveEffect key="p" />, <LayoutEffect key="l" />], container);
jest.runAllTimers();
expect(logs).toEqual([

@@ -1294,3 +1265,3 @@ 'Passive',

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -1324,3 +1295,3 @@ 'Committed state when effect was fired: 1',

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Schedule update [0]', 'Count: 0']);

@@ -1333,3 +1304,3 @@

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Schedule update [1]', 'Count: 1']);

@@ -1362,2 +1333,3 @@ });

// Rendering again should flush the previous commit's effects
jest.runAllTimers();
render(<Counter count={1} />, container);

@@ -1368,3 +1340,3 @@ expect(logs).toEqual(['Schedule update [0]', 'Count: 0', 'Count: 0']);

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Schedule update [1]', 'Count: 1']);

@@ -1395,3 +1367,2 @@ expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 1');

expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 0');
logs = [];

@@ -1401,3 +1372,4 @@ // Enqueuing this update forces the passive effect to be flushed --

_updateCount(2);
expect(logs).toEqual(['Will set count to 1', 'Count: 1', 'Count: 2']);
jest.runAllTimers();
expect(logs).toEqual(['Will set count to 1', 'Count: 2']);
expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 2');

@@ -1436,3 +1408,3 @@ });

logs = [];
flushPassiveEffects();
jest.runAllTimers();
// There were multiple updates, but there should only be a

@@ -1475,3 +1447,3 @@ // single render

logs = [];
flushPassiveEffects();
jest.runAllTimers();
// There were multiple updates, but there should only be a

@@ -1504,3 +1476,3 @@ // single render

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did create [0]']);

@@ -1513,3 +1485,3 @@

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -1541,3 +1513,3 @@ 'Did destroy [0]',

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did create [0]']);

@@ -1548,3 +1520,3 @@

// TODO
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did destroy [0]']);

@@ -1575,3 +1547,3 @@ // TODO

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did create [0]']);

@@ -1584,3 +1556,3 @@

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([]);

@@ -1591,3 +1563,3 @@

// TODO
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did destroy [0]']);

@@ -1618,3 +1590,3 @@ expect(container.childNodes).toEqual([]);

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did create']);

@@ -1627,3 +1599,3 @@

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did destroy', 'Did create']);

@@ -1634,3 +1606,3 @@

// TODO
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Did destroy']);

@@ -1660,3 +1632,3 @@ expect(container.childNodes).toEqual([]);

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -1671,3 +1643,3 @@ 'Did commit 1 [0]',

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -1705,3 +1677,3 @@ 'Did commit 1 [1]',

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Mount A [0]', 'Mount B [0]']);

@@ -1713,3 +1685,3 @@ logs = [];

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -1751,3 +1723,3 @@ 'Unmount A [0]',

// TODO
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual(['Unmount: 1']);

@@ -1802,3 +1774,3 @@ expect(container.childNodes).toEqual([]);

expect(container.childNodes[2].childNodes[0].data).toEqual('0');
flushPassiveEffects();
jest.runAllTimers();
expect(childAUpdateNum).toEqual(2);

@@ -1852,3 +1824,3 @@ expect(parentUpdateNum).toEqual(2);

logs = [];
flushPassiveEffects();
jest.runAllTimers();
expect(logs).toEqual([

@@ -2006,2 +1978,3 @@ 'Unmount normal [current: 1]',

counter.current.dispatch(INCREMENT);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 1');

@@ -2038,2 +2011,3 @@ // Intentionally not updated because of [] deps:

counter.current.dispatch(INCREMENT);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 1');

@@ -2078,2 +2052,3 @@ expect(counter.current.count).toBe(1);

counter.current.dispatch(INCREMENT);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 1');

@@ -2085,2 +2060,3 @@ expect(counter.current.count).toBe(1);

render(<Counter ref={counter} />, container);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toEqual('Count: 1');

@@ -2087,0 +2063,0 @@ expect(counter.current.count).toBe(1);

@@ -21,8 +21,10 @@ /* @jsx createElement */

beforeEach(() => {
beforeEach(function() {
Host.driver = ServerDriver;
jest.useFakeTimers();
});
afterEach(() => {
afterEach(function() {
Host.driver = null;
jest.useRealTimers();
});

@@ -114,3 +116,3 @@

render(<Child number="4" />, container2);
expect(container2.childNodes).toBe([]);
expect(container2.childNodes).toEqual([]);
}

@@ -122,2 +124,3 @@ render() {

render(<App />, container);
jest.runAllTimers();
expect(Child).toHaveBeenCalledTimes(1);

@@ -124,0 +127,0 @@ expect(container2.childNodes[0].childNodes[0].data).toBe('4');

@@ -37,3 +37,3 @@ import Host from './vdom/host';

if (typeof ref === 'string' && !ownerComponent) {
console.warn('createElement: adding a string ref outside the component’s render() method.');
console.error('createElement: adding a string ref "' + ref + '" outside the render method.');
}

@@ -40,0 +40,0 @@

import Host from './vdom/host';
import { schedule, flush } from './vdom/scheduler';
import { scheduleEffect, flushEffect } from './vdom/scheduler';
import { is } from './vdom/shallowEqual';

@@ -45,2 +45,7 @@

const setState = newState => {
// Flush effects first when not in effect
if (!Host.isUpdating) {
flushEffect();
}
const hook = hooks[hookID];

@@ -56,10 +61,7 @@ const eagerState = hook[2];

// After this one render finish, will containue run.
hook[2] = newState;
if (getCurrentInstance() === currentInstance) {
hook[2] = newState;
// Marked as is scheduled that could finish hooks.
currentInstance.isScheduled = true;
} else {
!Host.isUpdating && flush();
hook[2] = newState;
currentInstance.update();

@@ -107,3 +109,3 @@ }

const create = (immediately) => {
if (!immediately && defered) return schedule(() => create(true));
if (!immediately && defered) return scheduleEffect(() => create(true));
const { current } = create;

@@ -121,3 +123,3 @@ if (current) {

const destory = (immediately) => {
if (!immediately && defered) return schedule(() => destory(true));
if (!immediately && defered) return scheduleEffect(() => destory(true));
const { current } = destory;

@@ -222,2 +224,7 @@ if (current) {

const dispatch = action => {
// Flush effects first when not in effect
if (!Host.isUpdating) {
flushEffect();
}
const hook = hooks[hookID];

@@ -232,4 +239,2 @@ // Reducer will update in the next render, before that we add all

} else {
!Host.isUpdating && flush();
const currentState = queue.eagerState;

@@ -236,0 +241,0 @@ const eagerReducer = queue.eagerReducer;

@@ -1,10 +0,12 @@

import createElement from './createElement';
import createContext from './createContext';
import createRef from './createRef';
import {useState, useContext, useEffect, useLayoutEffect, useRef, useCallback, useMemo, useReducer, useImperativeHandle} from './hooks';
import memo from './memo';
import Fragment from './fragment';
import render from './render';
import Component, { PureComponent } from './vdom/component';
import version from './version';
export createElement from './createElement';
export createContext from './createContext';
export createRef from './createRef';
export forwardRef from './forwardRef';
export {useState, useContext, useEffect, useLayoutEffect, useRef, useCallback, useMemo, useReducer, useImperativeHandle} from './hooks';
export memo from './memo';
export Fragment from './fragment';
export render from './render';
export Component, { PureComponent } from './vdom/component';
export version from './version';
import Host from './vdom/host';

@@ -15,3 +17,3 @@ import Instance from './vdom/instance';

const shared = {
export const shared = {
Host,

@@ -22,11 +24,1 @@ Instance,

};
export {
createElement, createRef, createContext,
useState, useContext, useEffect, useLayoutEffect, useRef, useCallback, useMemo, useReducer, useImperativeHandle,
Component, PureComponent,
Fragment, memo,
render,
version,
shared
};

@@ -6,2 +6,3 @@ /* eslint-disable react/no-did-mount-set-state */

import renderer from '../renderer';
import { flush } from '../../vdom/scheduler';

@@ -90,2 +91,3 @@ describe('renderer', () => {

var component = renderer.create(<MyComponent />);
flush();
expect(component.toJSON()).toEqual({

@@ -126,2 +128,4 @@ tagName: 'DIV',

mouse.handleMoose();
flush();
expect(component.toJSON()).toEqual({

@@ -128,0 +132,0 @@ tagName: 'DIV',

import createElement from '../../createElement';
import Component from '../../vdom/component';
import renderer from '../renderer';
import { flush } from '../../vdom/scheduler';

@@ -54,2 +55,3 @@ const STATUS = {

tree = component.toJSON();
flush();
expect(tree).toMatchSnapshot();

@@ -61,3 +63,4 @@

tree = component.toJSON();
flush();
expect(tree).toMatchSnapshot();
});

@@ -23,2 +23,3 @@ /* @jsx createElement */

Host.driver = ServerDriver;
jest.useFakeTimers();
});

@@ -28,2 +29,3 @@

Host.driver = null;
jest.useRealTimers();
});

@@ -50,22 +52,7 @@

component.toggleActivatedState();
jest.runAllTimers();
expect(component.refs.x.tagName).toBe('B');
});
it('should cleanup even if render() fatals', function() {
class BadComponent extends Component {
render() {
throw new Error();
}
}
expect(Host.owner).toBe(null);
expect(function() {
render(<BadComponent />);
}).not.toThrow();
expect(Host.owner).toBe(null);
});
it('donot call render when setState in componentWillMount', function() {

@@ -209,2 +196,3 @@ let container = createNodeElement('div');

jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toBe('Caught an error: Hello.');

@@ -245,3 +233,3 @@ });

</ErrorBoundary>, container);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toBe('Caught an error: Hello.');

@@ -282,3 +270,3 @@ });

</ErrorBoundary>, container);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toBe('Caught an error: Hello.');

@@ -305,2 +293,3 @@ });

render(<BrokenRender />, container);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toBe('Caught an error: Hello.');

@@ -375,4 +364,4 @@ });

render(
<ErrorBoundary />, container);
render(<ErrorBoundary />, container);
jest.runAllTimers();
expect(container.childNodes.length).toBe(1);

@@ -407,4 +396,4 @@ expect(container.childNodes[0].childNodes[0].data).toBe('Caught an error: Hello.');

render(
<ErrorBoundary />, container);
render(<ErrorBoundary />, container);
jest.runAllTimers();
expect(container.childNodes.length).toBe(1);

@@ -469,3 +458,2 @@ expect(container.childNodes[0].childNodes[0].data).toBe('Caught an error: Hello.');

throw new Error();
return null;
}

@@ -515,2 +503,3 @@ componentDidMount() {

jest.runAllTimers();
expect(logs).toEqual([

@@ -554,2 +543,3 @@ 'componentWillMount1',

instance.setState({count: 1});
jest.runAllTimers();
expect(container.childNodes[0].tagName).toBe('DIV');

@@ -592,2 +582,3 @@ });

jest.runAllTimers();
expect(ops).toEqual([

@@ -605,3 +596,3 @@ 'render: 0',

instance.setState({tick: 2});
jest.runAllTimers();
expect(ops).toEqual([

@@ -637,2 +628,3 @@ 'render: 2',

render(<Foo />, container);
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toBe('5');

@@ -708,3 +700,3 @@ });

render(<Batch />, container2);
jest.runAllTimers();
expect(instance.state.x).toBe(1);

@@ -826,2 +818,3 @@ expect(child.state.y).toBe(2);

render(<App />, container);
jest.runAllTimers();
// Child1 Child2 appears only once

@@ -890,2 +883,3 @@ expect(logs).toEqual(['Child1', 'Parent1', 'Child2']);

});
jest.runAllTimers();

@@ -892,0 +886,0 @@ childNodes = container.childNodes;

@@ -8,2 +8,3 @@ 'use strict';

import render from '../../render';
import { flush } from '../scheduler';
import ServerDriver from 'driver-server';

@@ -25,2 +26,3 @@

Host.driver = ServerDriver;
jest.useFakeTimers();
});

@@ -30,2 +32,3 @@

Host.driver = null;
jest.useRealTimers();
});

@@ -138,5 +141,8 @@

expect(container.childNodes[0].childNodes[0].data).toBe('initial-initial');
instance.setState({bar: 'changed'});
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].data).toBe('changed-changed');
});
});

@@ -25,2 +25,3 @@ /* @jsx createElement */

Host.driver = ServerDriver;
jest.useFakeTimers();
});

@@ -30,2 +31,3 @@

Host.driver = null;
jest.useRealTimers();
});

@@ -122,2 +124,4 @@

jest.runAllTimers();
childNodes = container.childNodes;

@@ -177,2 +181,3 @@

let childNodes = container.childNodes;
jest.runAllTimers();

@@ -358,2 +363,4 @@ expect(childNodes.length).toBe(4);

jest.runAllTimers();
expect(childNodes.length).toBe(6);

@@ -370,2 +377,3 @@ expect(childNodes[0].childNodes[0].data).toBe('1');

});
jest.runAllTimers();

@@ -402,5 +410,8 @@ expect(childNodes.length).toBe(3);

expect(el.childNodes[0].childNodes).toEqual([]);
instance.setState({
count: 1
});
jest.runAllTimers();
expect(el.childNodes[0].childNodes[0].data).toBe('1');

@@ -438,2 +449,5 @@ expect(el.childNodes[0].childNodes[1].data).toBe('2');

});
jest.runAllTimers();
expect(el.childNodes[0].childNodes[0].data).toBe('1');

@@ -440,0 +454,0 @@ expect(el.childNodes[0].childNodes[1].data).toBe('2');

@@ -25,2 +25,3 @@ /* @jsx createElement */

Host.driver = ServerDriver;
jest.useFakeTimers();
});

@@ -30,2 +31,3 @@

Host.driver = null;
jest.useRealTimers();
});

@@ -149,3 +151,6 @@

expect(container.childNodes[0].childNodes[1].childNodes[0].data).toBe('2');
instance.setState({count: 1});
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].childNodes[0].data).toBe('2');

@@ -152,0 +157,0 @@ expect(container.childNodes[0].childNodes[1].childNodes[0].data).toBe('3');

@@ -25,2 +25,3 @@ /* @jsx createElement */

Host.driver = ServerDriver;
jest.useFakeTimers();
});

@@ -30,2 +31,3 @@

Host.driver = null;
jest.useRealTimers();
});

@@ -124,2 +126,3 @@

});
jest.runAllTimers();

@@ -160,3 +163,6 @@ childNodes = container.childNodes;

expect(container.childNodes[0].childNodes[4].childNodes[0].data).toBe('c');
instance.setState({count: 1});
jest.runAllTimers();
expect(container.childNodes[0].childNodes[0].childNodes[0].data).toBe('c');

@@ -163,0 +169,0 @@ expect(container.childNodes[0].childNodes[1].childNodes[0].data).toBe('e');

@@ -12,2 +12,3 @@ /* @jsx createElement */

Host.driver = ServerDriver;
jest.useFakeTimers();
});

@@ -17,2 +18,3 @@

Host.driver = null;
jest.useRealTimers();
});

@@ -35,8 +37,11 @@

component.setState({type: 'foo'});
jest.runAllTimers();
expect(renders).toBe(1);
component.setState({type: 'bar'});
jest.runAllTimers();
expect(renders).toBe(2);
component.setState({type: 'bar'});
jest.runAllTimers();
expect(renders).toBe(2);

@@ -61,3 +66,3 @@ });

component.setState({type: 'foo'});
jest.runAllTimers();
expect(renders).toBe(2);

@@ -64,0 +69,0 @@ });

@@ -14,2 +14,3 @@ 'use strict';

Host.driver = ServerDriver;
jest.useFakeTimers();
});

@@ -19,2 +20,3 @@

Host.driver = null;
jest.useRealTimers();
});

@@ -68,2 +70,4 @@

refHopsAround.moveRef();
jest.runAllTimers();
expect(refHopsAround.refs.divOneRef).toEqual(firstDiv);

@@ -74,2 +78,4 @@ expect(refHopsAround.refs.hopRef).toEqual(secondDiv);

refHopsAround.moveRef();
jest.runAllTimers();
expect(refHopsAround.refs.divOneRef).toEqual(firstDiv);

@@ -84,2 +90,4 @@ expect(refHopsAround.refs.divTwoRef).toEqual(secondDiv);

refHopsAround.moveRef();
jest.runAllTimers();
expect(refHopsAround.refs.hopRef).toEqual(firstDiv);

@@ -143,2 +151,4 @@ expect(refHopsAround.refs.divTwoRef).toEqual(secondDiv);

refHopsAround.moveRef();
jest.runAllTimers();
expect(refHopsAround.refs.divOneRef.id).toEqual(firstDiv);

@@ -149,2 +159,4 @@ expect(refHopsAround.refs.hopRef.id).toEqual(secondDiv);

refHopsAround.moveRef();
jest.runAllTimers();
expect(refHopsAround.refs.divOneRef.id).toEqual(firstDiv);

@@ -159,2 +171,4 @@ expect(refHopsAround.refs.divTwoRef.id).toEqual(secondDiv);

refHopsAround.moveRef();
jest.runAllTimers();
expect(refHopsAround.refs.hopRef.id).toEqual(firstDiv);

@@ -161,0 +175,0 @@ expect(refHopsAround.refs.divTwoRef.id).toEqual(secondDiv);

@@ -26,2 +26,4 @@ import Host from './host';

this.state = {};
if (pureRender.forwardRef) {

@@ -41,3 +43,3 @@ this.prevForwardRef = this.forwardRef = ref;

break;
};
}
}

@@ -113,3 +115,4 @@

update() {
this.forceUpdate();
this._internal._isPendingForceUpdate = true;
this.setState({});
}

@@ -116,0 +119,0 @@

@@ -20,6 +20,13 @@ /*

if (!ownerComponent) {
throw Error('Multiple version of Rax used in project.');
return console.error('ref: multiple version of Rax used in project.');
}
let instance = component.getPublicInstance();
if (process.env.NODE_ENV !== 'production') {
if (instance == null) {
console.error('ref: do not attach ref to function components because they don’t have instances.');
}
}
if (typeof ref === 'function') {

@@ -26,0 +33,0 @@ ref(instance);

@@ -8,6 +8,4 @@ import Component from './component';

super();
this.state = {
// Using fragment instead of null for avoid create a comment node when init mount
element: []
};
// Using fragment instead of null for avoid create a comment node when init mount
this.element = [];
this.rootID = rootID++;

@@ -25,9 +23,8 @@ }

update(element) {
this.setState({
element
});
this.element = element;
this.forceUpdate();
}
render() {
return this.state.element;
return this.element;
}

@@ -34,0 +31,0 @@ }

@@ -0,44 +1,51 @@

let scheduler;
if (process.env.NODE_ENV !== 'production') {
scheduler = (callback) => {
setTimeout(callback);
};
} else {
scheduler = typeof Promise == 'function' ? Promise.prototype.then.bind(Promise.resolve()) : setTimeout;
}
let performUpdate = null;
let updateCallbacks = [];
let effectCallbacks = [];
const setImmediatePolyfill = job => {
return setTimeout(job, 0);
}; // 0s
const scheduleImmediateCallback = typeof setImmediate === 'undefined' ?
setImmediatePolyfill : setImmediate;
const cancelImmediateCallback = typeof clearImmediate === 'undefined' ?
clearTimeout : clearImmediate;
let beforeNextRenderCallbacks = [];
let beforeNextRenderCallbackId;
// Commit before next render
function commit() {
let preCallbacks = beforeNextRenderCallbacks;
beforeNextRenderCallbacks = [];
preCallbacks.forEach(callback => callback());
preCallbacks = null;
// Exec callback maybe schedule a work
performUpdate();
}
// Schedule before next render
export const schedule = (callback) => {
if (beforeNextRenderCallbacks.length === 0) {
beforeNextRenderCallbackId = scheduleImmediateCallback(commit);
export function schedule(callback) {
if (updateCallbacks.length === 0) {
scheduler(flush);
}
beforeNextRenderCallbacks.push(callback);
};
updateCallbacks.push(callback);
}
// Flush before next render
export function flush() {
if (beforeNextRenderCallbacks.length !== 0) {
cancelImmediateCallback(beforeNextRenderCallbackId);
commit();
flushEffect();
let callbacks = updateCallbacks;
if (callbacks.length !== 0) {
updateCallbacks = [];
callbacks.forEach(callback => callback());
// Exec callback maybe schedule a work
performUpdate();
}
}
export function scheduleEffect(callback) {
if (effectCallbacks.length === 0) {
scheduler(flushEffect);
}
effectCallbacks.push(callback);
}
export function flushEffect() {
let callbacks = effectCallbacks;
if (callbacks.length !== 0) {
effectCallbacks = [];
callbacks.forEach(callback => callback());
}
}
export function setUpdater(handle) {
performUpdate = handle;
}
import Host from './host';
import { flush, setUpdater } from './scheduler';
import { flushEffect, schedule, setUpdater } from './scheduler';

@@ -80,17 +80,17 @@ // Dirty components store

if (Host.isUpdating) {
return;
return schedule(performUpdate);
}
let dirties;
let component;
while (dirtyComponents.length > 0) {
// Before next render, we will flush all the PassiveEffects
flush();
let dirties = dirtyComponents;
if (dirties.length > 0) {
// Before next render, we will flush all the effects
flushEffect();
dirtyComponents = [];
// Since reconciling a component higher in the owner hierarchy usually (not
// always -- see shouldComponentUpdate()) will reconcile children, reconcile
// them before their children by sorting the array.
dirties = dirtyComponents.sort(mountOrderComparator);
// Reset dirtyComponents, using to collect dirtyComponent
// generated by the next render
dirtyComponents = [];
if (dirties.length > 1) {
dirties = dirties.sort(mountOrderComparator);
}

@@ -103,7 +103,16 @@ while (component = dirties.pop()) {

function scheduleUpdate(component) {
function scheduleUpdate(component, shouldAsyncUpdate) {
if (dirtyComponents.indexOf(component) < 0) {
dirtyComponents.push(component);
}
performUpdate();
if (shouldAsyncUpdate) {
// If have been scheduled before, don't not need schedule again
if (dirtyComponents.length > 1) {
return;
}
schedule(performUpdate);
} else {
performUpdate();
}
}

@@ -118,4 +127,2 @@

!Host.isUpdating && flush();
if (callback) {

@@ -130,3 +137,2 @@ enqueueCallback(internal, callback);

enqueueState(internal, partialState);
// State pending when request update in componentWillMount and componentWillReceiveProps,

@@ -136,3 +142,3 @@ // isPendingState default is false value (false or null) and set to true after componentWillReceiveProps,

if (!internal._isPendingState && hasComponentRendered) {
scheduleUpdate(component);
scheduleUpdate(component, true);
}

@@ -139,0 +145,0 @@ } else {

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc