import Request from '../core/Request' import Listener, { RawListenerType } from '../core/Listener' import Throttle, { RawThrottleType } from '../core/Throttle' import NervNode from '../core/NervNode' import Validator from '../core/Validator' export default class NervAdHoc { public readonly nervNode: NervNode protected inThrottle: RawThrottleType = null protected outThrottle: RawThrottleType = null private name: string private centerNervNode: NervNode constructor() { this.name = this.constructor.name const it = new Throttle(this.name, this.inThrottle) const ot = new Throttle(this.name, this.outThrottle) const lsr = new Listener(this.name, this.listenNerv()) this.nervNode = new NervNode(this.name, 'ComponentNode', lsr, it, ot, null) this.nervAdHocWillMount() this.nervAdHocDidMount() } public nervAdHocWillMount() {} public nervAdHocDidMount() {} public listenNerv() :RawListenerType { return {} } public bindAdHoc(child: NervAdHoc) { child.nervNode.setCenterNervNode(this.centerNervNode) this.nervNode.bind(child.nervNode) } public unbindAdHoc(child: NervAdHoc) { this.nervNode.unbind(child.nervNode) } protected dispatch(path: string, data: any = null, async: boolean = true) :Promise<{data: any, error: any}> { return new Promise(resolve => { const request = new Request(path, data, resolve, async) this.nervNode.dispatch(request) }) } protected dispatchUp(path: string, data: any = null, async: boolean = true) :Promise<{data: any, error: any}> { return new Promise(resolve => { const request = new Request(path, data, resolve, async) this.nervNode.dispatchUp(request) }) } protected dispatchDown(path: string, data: any = null, async: boolean = true) :Promise<{data: any, error: any}> { return new Promise(resolve => { const request = new Request(path, data, resolve, async) this.nervNode.dispatchDown(request) }) } protected broadcast(path: string, data: any = null, async: boolean = true) :Promise<{data: any, error: any}> { return new Promise(resolve => { const request = new Request(path, data, resolve, async) this.nervNode.broadcast(request) }) } }