From aaa7da2243f7a980cad13ba9bc343fa1dd6b2c00 Mon Sep 17 00:00:00 2001 From: Nick Bradley Date: Mon, 12 Jun 2023 16:13:11 -0600 Subject: [PATCH 1/2] Fix: Actions with options may run out of order --- src/core/action_descriptor.ts | 7 +++++++ src/core/dispatcher.ts | 6 ++++-- src/tests/modules/core/action_ordering_tests.ts | 12 ++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/core/action_descriptor.ts b/src/core/action_descriptor.ts index 917bf240..55d5a0a9 100644 --- a/src/core/action_descriptor.ts +++ b/src/core/action_descriptor.ts @@ -29,6 +29,13 @@ export const defaultActionDescriptorFilters: ActionDescriptorFilters = { }, } +export const nativeActionDescriptors: string[] = [ + "capture", + "once", + "passive", + "!passive" +] + export interface ActionDescriptor { eventTarget: EventTarget eventOptions: AddEventListenerOptions diff --git a/src/core/dispatcher.ts b/src/core/dispatcher.ts index 04a3bb27..a7c317bb 100644 --- a/src/core/dispatcher.ts +++ b/src/core/dispatcher.ts @@ -2,6 +2,7 @@ import { Application } from "./application" import { Binding } from "./binding" import { BindingObserverDelegate } from "./binding_observer" import { EventListener } from "./event_listener" +import { nativeActionDescriptors } from "./action_descriptor" export class Dispatcher implements BindingObserverDelegate { readonly application: Application @@ -112,8 +113,9 @@ export class Dispatcher implements BindingObserverDelegate { private cacheKey(eventName: string, eventOptions: any): string { const parts = [eventName] - Object.keys(eventOptions) - .sort() + + nativeActionDescriptors + .filter((key) => key in eventOptions) .forEach((key) => { parts.push(`${eventOptions[key] ? "" : "!"}${key}`) }) diff --git a/src/tests/modules/core/action_ordering_tests.ts b/src/tests/modules/core/action_ordering_tests.ts index 317bd269..f88be27d 100644 --- a/src/tests/modules/core/action_ordering_tests.ts +++ b/src/tests/modules/core/action_ordering_tests.ts @@ -34,6 +34,18 @@ export default class ActionOrderingTests extends LogControllerTestCase { ) } + async "test adding an action to the left with a :stop modifier"() { + this.actionValue = "c#log3:stop c#log d#log2" + await this.nextFrame + await this.triggerEvent(this.buttonElement, "click") + + this.assertActions( + { name: "log3", identifier: "c", eventType: "click", currentTarget: this.buttonElement }, + { name: "log", identifier: "c", eventType: "click", currentTarget: this.buttonElement }, + { name: "log2", identifier: "d", eventType: "click", currentTarget: this.buttonElement } + ) + } + async "test removing an action from the right"() { this.actionValue = "c#log d#log2" await this.nextFrame From 6d8a6aa6c053f0aa60918992c62325d3eacfe6b3 Mon Sep 17 00:00:00 2001 From: Nick Bradley Date: Mon, 12 Jun 2023 23:45:17 -0600 Subject: [PATCH 2/2] Lint & prettier --- src/core/action_descriptor.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/core/action_descriptor.ts b/src/core/action_descriptor.ts index 55d5a0a9..97ba835f 100644 --- a/src/core/action_descriptor.ts +++ b/src/core/action_descriptor.ts @@ -29,12 +29,7 @@ export const defaultActionDescriptorFilters: ActionDescriptorFilters = { }, } -export const nativeActionDescriptors: string[] = [ - "capture", - "once", - "passive", - "!passive" -] +export const nativeActionDescriptors: string[] = ["capture", "once", "passive", "!passive"] export interface ActionDescriptor { eventTarget: EventTarget