minska-react
Version:
React helpers for minska
2 lines (1 loc) • 3.42 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.MinskaReact=e.MinskaReact||{},e.React)}(this,function(e,t){"use strict";t="default"in t?t.default:t;var n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},i=function(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n},c=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},p=function(e){return e},u={send:t.PropTypes.func.isRequired,subscribe:t.PropTypes.func.isRequired,unsubscribe:t.PropTypes.func.isRequired},a=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:p;return function(p){var a,f;return f=a=function(u){function a(t,r){n(this,a);var s=c(this,(a.__proto__||Object.getPrototypeOf(a)).call(this,t,r)),i=p.displayName||p.name||"Component",u="connect("+i+")";if(s.connectKey=u+":"+Math.random().toString(36).substr(2,8),s.store=r.store||t.store,!s.store)throw new Error("Could not find 'store' in either the context or props of component '"+u+"'. Either wrap the root component in <Provider>, or explicitly pass 'store' as a prop to '"+u+"'.");return s.state=o({},e(s.store.state,t)),s.onUpdate=s.onUpdate.bind(s),s.send=s.send.bind(s),s}return s(a,u),r(a,[{key:"componentWillMount",value:function(){this.store.subscribe("onChange",this.connectKey,this.onUpdate)}},{key:"componentWillUnmount",value:function(){this.store.unsubscribe(this.connectKey)}},{key:"onUpdate",value:function(t){this.setState(o({},e(t,this.props)))}},{key:"send",value:function(){var e;(e=this.store).send.apply(e,arguments)}},{key:"render",value:function(){var e=this.props,n=(e.store,i(e,["store"]));return t.createElement(p,o({},n,this.state,{send:this.send}))}}]),a}(t.PureComponent),a.contextTypes={store:t.PropTypes.shape(u)},a.propTypes={store:t.PropTypes.shape(u)},f}},f=function(e){function t(){var e,r,o,s;n(this,t);for(var i=arguments.length,p=Array(i),u=0;u<i;u++)p[u]=arguments[u];return r=o=c(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(p))),o.state={store:o.props.store},s=r,c(o,s)}return s(t,e),r(t,[{key:"getChildContext",value:function(){return{store:this.state.store}}},{key:"render",value:function(){return this.props.children}}]),t}(t.PureComponent);f.propTypes={children:t.PropTypes.node.isRequired,store:t.PropTypes.object.isRequired},f.childContextTypes={store:t.PropTypes.object},e.connect=a,e.Provider=f,Object.defineProperty(e,"__esModule",{value:!0})});