Skip to content

Instantly share code, notes, and snippets.

@zemlanin
Created July 20, 2015 15:12
Show Gist options
  • Save zemlanin/f4c6dfbe66a75ce48b18 to your computer and use it in GitHub Desktop.
Save zemlanin/f4c6dfbe66a75ce48b18 to your computer and use it in GitHub Desktop.
react/rxjs wrapper
_ = require 'lodash'
{addons: {cloneWithProps}} = require 'react'
echoEvent = (rxId, eventStream, eventName, ev) ->
eventStream.onNext {
ev
rxId
type: eventName
}
module.exports = Echo = ({rxId, eventStream, events}, element) ->
newProps = {}
events = if _.isArray events
events
else if _.isString events
[events]
else
[]
for eventName in events
newProps[eventName] = echoEvent.bind(null, rxId, eventStream, eventName)
cloneWithProps(
element
newProps
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment