adonisjs-livewire
Version:
A front-end framework for AdonisJS
41 lines (40 loc) • 1.04 kB
JavaScript
export default class ComponentContext {
component;
mounting;
effects = {};
memo = {};
constructor(component, mounting = false) {
this.component = component;
this.mounting = mounting;
}
addEffect(key, value) {
if (typeof key === 'object') {
Object.entries(key).forEach(([iKey, iValue]) => this.addEffect(iKey, iValue));
return;
}
this.effects[key] = value;
}
pushEffect(key, value, iKey) {
if (!this.effects[key])
this.effects[key] = {};
if (iKey !== undefined) {
this.effects[key][iKey] = value;
}
else {
this.effects[key].push(value);
}
}
addMemo(key, value) {
this.memo[key] = value;
}
pushMemo(key, value, iKey) {
if (!this.memo[key])
this.memo[key] = [];
if (iKey !== undefined) {
this.memo[key][iKey] = value;
}
else {
this.memo[key].push(value);
}
}
}