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

Event dispatcher preprocessor #11

Open
JonathanxD opened this issue Dec 15, 2019 · 0 comments
Open

Event dispatcher preprocessor #11

JonathanxD opened this issue Dec 15, 2019 · 0 comments
Assignees
Milestone

Comments

@JonathanxD
Copy link
Contributor

JonathanxD commented Dec 15, 2019

Proposal

Provide a preprocessing step in event dispatch, allowing it to flexibly change channels of the event before sending it through dispatch logic, or cancelling them.

Example

Event:

interface AccountMoneyChangeEvent : Event {
    val amount: Int
}

Preprocessor:

class AccountMoneyChangeEventPreprocessor : EventDispatchPreprocessor<AccountMoneyChangeEvent> {
    fun onPreprocess(event: AccountMoneyChangeEvent, dispatch: DispatchConfiguration) {
        if (event.amount < 0) {
            dispatch.channels += ChannelSet.Include("withdraw")
        } else if (event.amount > 0) {
            dispatch.channels += ChannelSet.Include("deposit")
        } else {
            dispatch.cancel()
        }
    }
}

eventManager.registerPreprocessor<AccountMoneyChangeEvent>(AccountMoneyChangeEventPreprocessor())

Also, if Characteristics get implemented, the preprocessor could also change characteristics of events, but this will occur after Factory Characteristic Handling, so the preprocessor will have priority.

Downsides

A Dispatch Preprocessor could make it harder to figure why a event is not being dispatched as expected.

@JonathanxD JonathanxD added this to the 1.9 milestone Dec 15, 2019
@JonathanxD JonathanxD self-assigned this Dec 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant