Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andres-torres-marroquin/813ad20c95119ed0d7953abca7560314 to your computer and use it in GitHub Desktop.
Save andres-torres-marroquin/813ad20c95119ed0d7953abca7560314 to your computer and use it in GitHub Desktop.
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