Skip to content
New issue

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

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

Already on GitHub? # to your account

Support for Events or Pub/Sub #23

Closed
tannerlinsley opened this issue Oct 21, 2015 · 9 comments
Closed

Support for Events or Pub/Sub #23

tannerlinsley opened this issue Oct 21, 2015 · 9 comments

Comments

@tannerlinsley
Copy link
Contributor

After discussing a few awesome ideas with @esjewett, I feel that there is a need to think about some integration points for crossfilter. One in particular is some way to know externally if the state or data inside a crossfilter has changed. Adding, removing, and filtering data are the three actions that come to mind.

In our current in-house solution, we are following up all of our calls to these crossfilter methods with a pup-sub like system. This works great for us, but breaks down when anything outside of our system (plugins, reductio, etc) call these methods for us.

I think it would be much easier to support some type of pub/sub support to use as an integration point.

The specific use case that sparked this conversation is my obsession with post-aggregations (think change stats for certain assessors eg. minChange) that can't be performed inside reduce functions, and must be applied after data is done changing (after any significant event in crossfilter).

Thoughts?

@tannerlinsley tannerlinsley changed the title Support for Event Callbacks Support for Events or Pub/Sub Oct 21, 2015
@tannerlinsley
Copy link
Contributor Author

For reference: crossfilter/reductio#25

@derekperkins
Copy link
Member

+:100: What would be the integration path? Would there be an extra function along the lines of enableCallbacks or is the performance hit when there are no listeners insignificant?

@tannerlinsley
Copy link
Contributor Author

I don't think it would affect crossfilter performance almost at all. Obviously you would be able to do what ever you want in those callbacks, so you personally could make it slow, but this is simply "Hi, I'm crossfilter. Just so you know, I just added/removed/filtered records." Possibly one liners here and there throughout the code to trigger those callbacks.

@tannerlinsley
Copy link
Contributor Author

There is also the question of how those callbacks would be registered. I'm sure we've all used tons of ways to register and deregister callbacks. I personally enjoy when an addCallback type function returns a function that in turn deregisters it. Much like angular.js $scope events.

@tannerlinsley
Copy link
Contributor Author

At this point, @esjewett also mentioned just starting with a high level onChange event to handle everything, and that as soon as we start popping in integration points, things could get crazy going forward unless they're well structured and absolutely needed.

@derekperkins
Copy link
Member

I'd say go ahead and submit a PR so we can use that as a base for discussion. If you and @esjewett are behind it, let's get started.

@esjewett
Copy link
Member

PR would make sense. Want to get @gordonwoodhull's input as well. As far as the PR, I would recommend invoking the callback at the end of crossfilter.add, crossfilter.remove, and dimension.filter methods rather than trying to plug into the internal Crossfilter listener system.

@tannerlinsley
Copy link
Contributor Author

@esjewett, I agree. The internal system is very fitted to crossfilter.
Might be hard to reason about for our purposes. I'll work up a PR by the
end of the day.

@gordonwoodhull
Copy link
Contributor

This fits into the goal of making crossfilter more transparent. I appreciate that the original authors wanted to keep the API small, but it's kind of hard to use crossfilter as the point of integration between different modules which don't know about each other. And we naturally end up using it that way.

Obviously the callbacks should report the major operation, rather than row-by-row changes.

The internal listeners look like they do almost what we want, but they seem to do a bit more - in particular it looks like the filter listener is something quite different. I agree it's probably better to separate these.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants