Custom callbacks for filters #36

scottdavis opened this Issue Jun 4, 2012 · 6 comments


None yet

3 participants

FSSM had a way you could filter on globs with different callback methods then the global scope.


implementation in compass

Im fine with implementing this as a pull request but I want to start the discussion that it is something listen wants to support.

So in listen something like

listen.filter("som/glob/**/*")  do | modified, added, removed |
  ... do something cool

Hi Scott,

Listen use the Find Ruby class to traverse all paths, so I'm not sure that global scope could be easily added. What do you think @Maher4Ever?


As @thibaudgg stated, this can be a little challenging to implement. Listen was not designed to handle this usecase. Adding it now is possible, but I'm a little bit concerned with the semantics of the API. Listen already has a filter method which takes regex patterns, but that's only a method name and can easily be changed.
Listen also has two ways to register a "global" callback, namely through the change method or by passing a block to the initializer. The change method can be used to change the callback if needed.

Adding a method which adds a callback (via a passed block) for a specific pattern would mean one of two things for multiple calls:

  • There can only be one callback for a specific pattern, because subsequent calls would replace the old callback with the new one. This is how the global callback works now.
  • Subsequent calls with the same pattern would keep adding callbacks for that pattern. This means a callback could not be replaced and/or removed.

Maybe a new class could be introduced to handle this situation. Something like:

listener ='dir') { ... }

# Simple usecases can be implmented like:
listener.filtered_callback(%r{your_filter}) { ... } 

# Advanced usecases:
callbacks ={your_filter})

# Replace a callback
callbacks.replace(&callback2, &callback3)

# Remove a callback

# Register the callbacks with the listener

Even the current change method could take an object (maybe the same Listen::CallbacksSet without a filter) to allow registering multiple "global" callbacks.

These are all ideas after all, so I'm interested in what you think about them.

I was more wanting to start the question of is liten going to support feature sets of FSSM as part of its goal of becoming the replacement. I can have around and fake this functionally using a global call back i just wanted to make sure that this wasn't something that was missed.


I'm not sure that all features (or way of doing things) of FSSM would fit properly in Listen, the more import ant I think is that the same achievement can be done (even if it needs to be implemented differently on the client side).

@ttilley seems ok for you?

i ended up hacking around this you can check it out here if your interested

@scottdavis scottdavis closed this Oct 20, 2012

@scottdavis great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment