enh(interact) generalize (inter-)actions and make it more flexible
This commit is contained in:
@@ -3,7 +3,7 @@ import Registry from '../core/Registry';
|
||||
import Logger from '../core/Logger';
|
||||
|
||||
export default class Interact extends CetraPlugin {
|
||||
static #actions = [
|
||||
static #commands = [
|
||||
'on',
|
||||
'off',
|
||||
'click',
|
||||
@@ -28,7 +28,7 @@ export default class Interact extends CetraPlugin {
|
||||
`no cetra instance found: ${this.#cetraIdentifier}`
|
||||
);
|
||||
|
||||
cetra.registerCommands(Interact.#actions, this.#pluginName);
|
||||
cetra.registerCommands(Interact.#commands, this.#pluginName);
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ export default class Interact extends CetraPlugin {
|
||||
throw new Error(
|
||||
`no cetra instance found: ${this.#cetraIdentifier}`
|
||||
);
|
||||
return (action ? [action] : Interact.#actions)
|
||||
return (action ? [action] : Interact.#commands)
|
||||
.map((action) =>
|
||||
[
|
||||
`[data-${cetra.getOption('selector')}-${action}]`,
|
||||
@@ -70,7 +70,7 @@ export default class Interact extends CetraPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
let [action, method, varName] = (
|
||||
let [action, command, ...options] = (
|
||||
el.getAttribute(`data-${cetra.getOption('selector')}-on`) ||
|
||||
el.getAttribute(`${cetra.getOption('selector')}-on`) ||
|
||||
''
|
||||
@@ -82,7 +82,7 @@ export default class Interact extends CetraPlugin {
|
||||
// if there is a command named like the action
|
||||
// and if so it gives the action to the appropriate
|
||||
// component
|
||||
cetra.exec(method, varName, componentId, e);
|
||||
cetra.exec(componentId, { command, options, e });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user