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

making trim-v before/after symmetrical #283

Closed
wants to merge 1 commit into from
Closed

Conversation

oliyh
Copy link
Contributor

@oliyh oliyh commented Dec 10, 2016

Clone of #280 for develop branch

Hello,

This change will put the untrimmed event vector back in the after phase, making it behave like the original middleware. This is generally a nice thing for interceptors to do, making them additive and not mutating, or at least idempotent.

This then allows other interceptors in the after phase to work better - middleware interceptors generally want to know what the event is called, because they're generic. For example, it lets me write the following improved schema check interceptor:

(defn valid-schema?
"validate the given db, writing any problems to console.error"
[db [event-name]]
(let [res (s/check schema db)]
(if (some? res)
(.error js/console (str "schema problem after event " event-name ":" res)))))
And use it in a stack of interceptors containing trim-v, as long as it's at the end (which it generally will be, because it cleans up the signatures of my event handlers but I don't want it for my middleware interceptors):

(def my-interceptors [(after valid-schema?)
trim-v])

@danielcompton
Copy link
Contributor

Thanks! Merged in ff7c175.

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

Successfully merging this pull request may close these issues.

None yet

2 participants