UNPKG

@ou-imdt/utils

Version:

Utility library for interactive media development

51 lines (40 loc) 1.67 kB
import DelegateChangeModule from '../../modules/DelegateChangeModule.js'; import { defaultState } from '../Base.js'; // defines a prop that holds global value mappings export const changeMap = Symbol('changeMap'); // defines a prop that holds type options for supported changes export const changeTargets = Symbol('changeTargets'); // defines a static class field that contains a list of handlers, searches this if null export const changeHandlers = Symbol('changeHandlers'); // defines a method that computes handler names for a given change and delegates to the handler, if defined const { map: defaultMap, targets: defaultTargets, handlers: defaultHandlers } = DelegateChangeModule[defaultState]; /** * @mixin * wraps DelegateChangeModule, exposing overridable defaults to subclasses * @member {DelegateChangeModule} - ??? */ export default (superClass) => class DelegateChangeMixin extends superClass { static get [changeMap]() { return defaultMap; }; static get [changeTargets]() { return defaultTargets; }; static get [changeHandlers]() { return defaultHandlers; }; #module; constructor() { super(); const { [changeMap]: map, [changeTargets]: targets, [changeHandlers]: handlers } = this.constructor; this.#module = new DelegateChangeModule(); this.#module.state = { ...(map === defaultMap) ? null : { map }, ...(targets === defaultTargets) ? null : { targets }, ...(handlers === defaultHandlers) ? { handlers: this } : { handlers } // check this!! }; } delegateChange(payload, target, thisArg = this) { return this.#module.delegateChange(payload, target, thisArg); } }