hele-hbus
Version:
HEle bindings for HBus.
1 lines • 2.44 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("hele"),require("hbus")):"function"==typeof define&&define.amd?define(["exports","hele","hbus"],t):t(e.HEle=e.HEle||{},e.HEle,e.HBus)}(this,function(e,t,r){"use strict";var n=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},o=function(){function defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,t,r){return t&&defineProperties(e.prototype,t),r&&defineProperties(e,r),e}}(),u=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){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},s=function(e){function Bus(e,t){n(this,Bus);var o=i(this,(Bus.__proto__||Object.getPrototypeOf(Bus)).call(this,e,t));return o.bus=new r.Bus(e.processor,e.defaultState),o.name=e.name,o}return u(Bus,e),o(Bus,[{key:"render",value:function(){return t.createElement(t.Context,{value:(e={},r=this.name,n=this.bus,r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e)},this.props.children);var e,r,n}}]),Bus}(t.Component);s.defaultProps={name:"hele-hbus-bus"};var p=function(e){function Subscription(e,t){n(this,Subscription);var r=i(this,(Subscription.__proto__||Object.getPrototypeOf(Subscription)).call(this,e,t)),o=(r.bus=t[e.bus]).getState();return r.state="prop"in e?o[e.prop]:o,r.subscriber=r.update.bind(r),r}return u(Subscription,e),o(Subscription,[{key:"onWillMount",value:function(){var e=this.props,t=this.bus,r=this.subscriber;"prop"in e?t.subscribeProp(e.prop,r):t.subscribe(r)}},{key:"render",value:function(){return this.props.children[0](this.state)}},{key:"onWillUnmount",value:function(){var e=this.props,t=this.bus,r=this.subscriber;"prop"in e?t.unsubscribeProp(e.prop,r):t.unsubscribe(r)}}]),Subscription}(t.Component);p.defaultProps={bus:"hele-hbus-bus"},e.defaultBusName="hele-hbus-bus",e.Bus=s,e.Subscription=p,Object.defineProperty(e,"__esModule",{value:!0})});