hele-hbus
Version:
HEle bindings for HBus.
1 lines • 880 B
JavaScript
import{Component as s,Context as r,createElement as t}from"hele";import{Bus as e}from"hbus";const u="hele-hbus-bus";class Bus$1 extends s{constructor(s,r){super(s,r),this.bus=new e(s.processor,s.defaultState),this.name=s.name}render(){return t(r,{value:{[this.name]:this.bus}},this.props.children)}}Bus$1.defaultProps={name:"hele-hbus-bus"};class Subscription extends s{constructor(s,r){super(s,r);const t=(this.bus=r[s.bus]).getState();this.state="prop"in s?t[s.prop]:t,this.subscriber=this.update.bind(this)}onWillMount(){const{props:s,bus:r,subscriber:t}=this;"prop"in s?r.subscribeProp(s.prop,t):r.subscribe(t)}render(){return this.props.children[0](this.state)}onWillUnmount(){const{props:s,bus:r,subscriber:t}=this;"prop"in s?r.unsubscribeProp(s.prop,t):r.unsubscribe(t)}}Subscription.defaultProps={bus:"hele-hbus-bus"};export{u as defaultBusName,Bus$1 as Bus,Subscription};