cyclejs/todomvc-cycle

compose+merge = one output event?

Closed this issue · 1 comments

I'm looking at a todo Intent and I see the input 'enter' key event stream get composed:

...
.compose(s => xs.merge(s, sources.DOM.select('.edit').events('blur', true)))
.map(ev => ({title: ev.target.value, type: 'doneEdit'}))

Why doesn't the map step not fire twice: once for the enter event and again for the merged DOM.select statement under the compose step? When I run the todo app in the debugger, I only see the map step called once... even though it looks like it should be called twice.

That's basically the same as

xs.merge(
  sources.DOM.select('.edit').events('keyup').filter(ev => ev.keyCode === ENTER_KEY),
  sources.DOM.select('.edit').events('blur', true)
)
.map(ev => ({title: ev.target.value, type: 'doneEdit'}))

Notice that the merge acts as an OR operator. So in xs.merge(a$, b$), the map will run for each time either a$ OR b$ emit.

I refactored that code recently in this onionify branch:

doneEdit$: xs.merge(editEnterEvent$, editBlurEvent$)