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

Improve event matching #8

Merged
merged 4 commits into from Jun 30, 2017
Merged

Improve event matching #8

merged 4 commits into from Jun 30, 2017

Conversation

stumitchell
Copy link
Contributor

Improve event matching by allowing event vectors and predicates in the required-events vector.

In day8 internal code some things that currently can't be handled by an async flow will be possible with these changes.

In this pr I attempt to address some of the comments in #6 but do it in a different way and do not cover all of the use cases.

In particular, the event-id->seen-fn is now handled by providing predicate fn's as used elsewhere in re-frame

@@ -8,7 +8,7 @@
"Dissociates an entry from a nested associative structure returning a new
nested structure. keys is a sequence of keys. Any empty maps that result
will not be present in the new structure.
The key thing is that 'm' remains identical? to istelf if the path was never present"
The key thing is that 'm' remains identical? to iself if the path was never present"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still misspelled comment iself

will either
- match only the event-keyword if a keyword is supplied
- match the entire event vector if a collection is supplied
- returns a the item itself if a fn is supplied"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

returns callback-pred if it is a fn

(defn seen-all-of?
[required-events seen-events]
(empty? (set/difference required-events seen-events)))
(every?
(fn [pred] (some (fn [e] (pred e)) seen-events))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can (some (fn [e] (pred e)) seen-events) be written as (some pred seen-events)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think every-pred might be better still here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every-pred? sadly won't work as the preds are applied in the inner fn.



(defn seen-any-of?
[required-events seen-events]
(some? (seq (set/intersection seen-events required-events))))
(some? (some
(fn [pred] (some (fn [e] (pred e)) seen-events))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can (some (fn [e] (pred e)) seen-events) be written as (some pred seen-events)? Perhaps it would also be easier to read if it was extracted into a let binding as any-pred?

@stumitchell stumitchell merged commit 1988c19 into master Jun 30, 2017
@stumitchell stumitchell deleted the pr-improved-event-matching branch June 30, 2017 04:57
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

3 participants