Created
December 10, 2018 16:08
-
-
Save andres-torres-marroquin/813ad20c95119ed0d7953abca7560314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useForceUpdate = -> useState()[1] | |
useDebouncedForceUpdate = _.debounce useForceUpdate, 100 | |
useCollectionBinder = (collection) -> | |
forceUpdate = useForceUpdate() | |
useEffect -> | |
collection.on 'add remove sort reset', forceUpdate | |
-> | |
collection.off 'add remove sort reset', forceUpdate | |
useDebouncedCollectionBinder = (collection) -> | |
debouncedForceUpdate = useDebouncedForceUpdate() | |
useEffect -> | |
collection.on 'add remove sort reset', debouncedForceUpdate | |
-> | |
collection.off 'add remove sort reset', debouncedForceUpdate | |
useModelBinder = (model) -> | |
forceUpdate = useForceUpdate() | |
useEffect -> | |
model.on 'change', forceUpdate | |
-> | |
model.off 'change', forceUpdate | |
useDebouncedModelBinder = (model) -> | |
debouncedForceUpdate = useDebouncedForceUpdate() | |
useEffect -> | |
model.on 'change', debouncedForceUpdate | |
-> | |
model.off 'change', debouncedForceUpdate | |
Friends = (props) -> | |
useCollectionBinder(props.collection) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment