Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Actions with options may run out of order #684

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/core/action_descriptor.ts
Expand Up @@ -29,6 +29,8 @@ export const defaultActionDescriptorFilters: ActionDescriptorFilters = {
},
}

export const nativeActionDescriptors: string[] = ["capture", "once", "passive", "!passive"]

export interface ActionDescriptor {
eventTarget: EventTarget
eventOptions: AddEventListenerOptions
Expand Down
6 changes: 4 additions & 2 deletions src/core/dispatcher.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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}`)
})
Expand Down
12 changes: 12 additions & 0 deletions src/tests/modules/core/action_ordering_tests.ts
Expand Up @@ -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
Expand Down