UNPKG

adonisjs-livewire

Version:

A front-end framework for AdonisJS

108 lines (107 loc) 3.23 kB
import { store } from './store.js'; export default class ComponentHook { setComponent(component) { this.component = component; } setApp(app) { this.app = app; } async callBoot(...params) { if (typeof this['boot'] === 'function') { //@ts-ignore await this['boot'](...params); } } async callMount(params) { if (typeof this['mount'] === 'function') { await this['mount'](params); } } async callHydrate(...params) { if (typeof this['hydrate'] === 'function') { //@ts-ignore await this['hydrate'](...params); } } async callUpdate(propertyName, fullPath, newValue) { const callbacks = []; if (typeof this['update'] === 'function') { callbacks.push(await this['update'](propertyName, fullPath, newValue)); } return async (...params) => { for (const callback of callbacks) { if (typeof callback === 'function') { await callback(...params); } } }; } callCall(method, params, returnEarly = false) { const callbacks = []; if (typeof this['call'] === 'function') { callbacks.push(this['call'](method, params, returnEarly)); } return (...args) => { callbacks.forEach((callback) => { if (typeof callback === 'function') { callback(...args); } }); }; } async callRender(...params) { const callbacks = []; if (typeof this['render'] === 'function') { callbacks.push(await this['render'](...params)); } return async (...args) => { for (const callback of callbacks) { if (typeof callback === 'function') { await callback(...args); } } }; } async callDehydrate(context) { if (typeof this['dehydrate'] === 'function') { await this['dehydrate'](context); } } async callDestroy(...params) { if (typeof this['destroy'] === 'function') { //@ts-ignore await this['destroy'](...params); } } async callException(...params) { if (typeof this['exception'] === 'function') { //@ts-ignore await this['exception'](...params); } } getProperties() { // return this.component?.all(); } getProperty(name) { return this.getProperties()?.[name]; } storeSet(key, value) { store(this.component).push(key, value); } storePush(key, value, iKey) { store(this.component).push(key, value, iKey); } storeGet(key, defaultValue = null) { return store(this.component).get(key) ?? defaultValue; } storeHas(key) { return store(this.component).has(key); } async boot(params) { } async mount(params) { } async hydrate(params) { } async dehydrate(context) { } async destroy(params) { } async exception(params) { } async call(method, params, returnEarly) { } }