arch-js / arch

Web application framework for React by Red Badger
BSD 3-Clause "New" or "Revised" License
170 stars 13 forks source link

Add has-listener to cursor #98

Closed tabazevedo closed 9 years ago

tabazevedo commented 9 years ago

Quick method to check if a cursor already has a listener at its current path.

Useful for dynamically generated cursor paths.

charypar commented 9 years ago

Interesting! I have no fundamental problem with it, just would be interested to know what the use-case is. :)

tabazevedo commented 9 years ago

We have a bunch of dynamically generated forms and we need an onChange listener to be created for them so we can handle submission isomorphically.

tabazevedo commented 9 years ago

The issue is they can be created multiple times if the user types in the the same or similar search query (its based on search results) but we don't want to create a new listener each time.

charypar commented 9 years ago

Hmm, should we just expose the listeners list on each cursor...? Is there any harm in doing that...? It would obvs be read only, cause of the way it's stored, but it sounds mildly useful.

tabazevedo commented 9 years ago

You mean like.. a cursor.listeners() method? otherwise you still need to do the finding by path (as they are only stored on the root) which would mean exposing path and root.

charypar commented 9 years ago

Yep, that's what I mean. cursor.listeners! -> [function, function, function].

charypar commented 9 years ago

@tabazevedo make sure you don't return the actual array though, we don't want people to push stuff into it. It should be fine to slice() clone it, it won't ever be massive...

tabazevedo commented 9 years ago

Added

charypar commented 9 years ago

Sorry to be a PITA, but now we don't need has-listener any more :)

tabazevedo commented 9 years ago

:sob: goodbye cruel world