react-native-portal
Version:
Translocate your render destination, using mitt. Built with react@16 and react-native in mind.
3 lines (2 loc) • 5.58 kB
JavaScript
var ReactNativePortal=function(t,e){"use strict";function n(t){return t=t||Object.create(null),{on:function(e,n){(t[e]||(t[e]=[])).push(n)},off:function(e,n){t[e]&&t[e].splice(t[e].indexOf(n)>>>0,1)},emit:function(e,n){(t[e]||[]).map(function(t){t(n)}),(t["*"]||[]).map(function(t){t(e,n)})}}}function r(t){return function(){return t}}function o(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}e=e&&e.hasOwnProperty("default")?e.default:e;var i=function(){};i.thatReturns=r,i.thatReturnsFalse=r(!1),i.thatReturnsTrue=r(!0),i.thatReturnsNull=r(null),i.thatReturnsThis=function(){return this},i.thatReturnsArgument=function(t){return t};var a=i,u=function(t){},c=function(t,e,n,r,o,i,a,c){if(u(e),!t){var l;if(void 0===e)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var p=[n,r,o,i,a,c],s=0;(l=new Error(e.replace(/%s/g,function(){return p[s++]}))).name="Invariant Violation"}throw l.framesToPop=1,l}},l=Object.getOwnPropertySymbols,p=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,f=(function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(t){r[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}()&&Object.assign,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"),h=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},y=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),m=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},b=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},v=function(){function t(t,e,n,r,o,i){i!==f&&c(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function e(){return t}t.isRequired=t;var n={array:t,bool:t,func:t,number:t,object:t,string:t,symbol:t,any:t,arrayOf:e,element:t,instanceOf:e,node:t,objectOf:e,oneOf:e,oneOfType:e,shape:e,exact:e};return n.checkPropTypes=a,n.PropTypes=n,n},d=function(t,e){return e={exports:{}},t(e,e.exports),e.exports}(function(t){t.exports=v()});d||console.warn("<react-native-portal> no PropTypes available");var O={portalSub:d.func,portalUnsub:d.func,portalSet:d.func,portalGet:d.func},_=function(t){function e(){var t,n,r,o;h(this,e);for(var i=arguments.length,a=Array(i),u=0;u<i;u++)a[u]=arguments[u];return n=r=b(this,(t=e.__proto__||Object.getPrototypeOf(e)).call.apply(t,[this].concat(a))),r.portals=new Map,r.portalSub=function(t,e){var n=r._emitter;n&&n.on(t,e)},r.portalUnsub=function(t,e){var n=r._emitter;n&&n.off(t,e)},r.portalSet=function(t,e){r.portals.set(t,e),r._emitter&&r._emitter.emit(t)},r.portalGet=function(t){return r.portals.get(t)||null},o=n,b(r,o)}return m(e,t),y(e,[{key:"getChildContext",value:function(){return{portalSub:this.portalSub,portalUnsub:this.portalUnsub,portalSet:this.portalSet,portalGet:this.portalGet}}},{key:"componentWillMount",value:function(){this._emitter=new n}},{key:"componentWillUnmount",value:function(){this._emitter=null}},{key:"render",value:function(){return this.props.children}}]),e}(e.Component);_.childContextTypes=O;var g=function(t){function e(){return h(this,e),b(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return m(e,t),y(e,[{key:"componentDidMount",value:function(){var t=this.props,e=t.name,n=t.children,r=this.context.portalSet;r&&r(e,n)}},{key:"componentWillReceiveProps",value:function(t){var e=this.props,n=t.name,r=t.children,o=this.context.portalSet;e.children!=t.children&&o&&o(n,r)}},{key:"componentWillUnmount",value:function(){var t=this.props.name,e=this.context.portalSet;e&&e(t,null)}},{key:"render",value:function(){this.props.name;return null}}]),e}(e.PureComponent);g.contextTypes=O;var P=function(t){function n(){var t,e,r,o;h(this,n);for(var i=arguments.length,a=Array(i),u=0;u<i;u++)a[u]=arguments[u];return e=r=b(this,(t=n.__proto__||Object.getPrototypeOf(n)).call.apply(t,[this].concat(a))),r.forceUpdater=function(){return r.forceUpdate()},o=e,b(r,o)}return m(n,t),y(n,[{key:"componentWillMount",value:function(){var t=this.props.name,e=this.context.portalSub;e&&e(t,this.forceUpdater)}},{key:"componentWillUnmount",value:function(){var t=this.props.name,e=this.context.portalUnsub;e&&e(t,this.forceUpdater)}},{key:"render",value:function(){var t=this.props,n=t.name,r=t.children,o=t.childrenProps,i=this.context.portalGet,a=i&&i(n)||r;return(o&&a?e.cloneElement(e.Children.only(a),o):a)||null}}]),n}(e.PureComponent);return P.contextTypes=O,t.PortalProvider=_,t.BlackPortal=g,t.WhitePortal=P,t}({},React);
//# sourceMappingURL=min.js.map