Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

project function of map is called twice #98

Closed
maiermic opened this issue Aug 5, 2016 · 2 comments
Closed

project function of map is called twice #98

maiermic opened this issue Aug 5, 2016 · 2 comments

Comments

@maiermic
Copy link
Contributor

maiermic commented Aug 5, 2016

The bug cyclejs/todomvc-cycle#35 in the TODO-MVC example of Cycles.js is introduced by [email protected] and is still present in the current latest release [email protected]. As far as I can tell, the project function of map (returned by amendStateWithChildren(sources.DOM)) in TaskList/index.js#L66 is called twice for each event. You can check this assumption by adding a debug statement in line 66

let amendedState$ = state$.debug('state')
    .map(amendStateWithChildren(sources.DOM))
    .remember();

and a log statement between line 14 and 15:

function amendStateWithChildren(DOMSource) {
  return function (todosData) {
    console.log('amendStateWithChildren', todosData);
    return {
      ...

If you run the app you see that each time you add an item to the list the console logs

state: Object {list: Array[1], filter: ""}
amendStateWithChildren Object {list: Array[1], filter: ""}
amendStateWithChildren Object {list: Array[1], filter: ""}

or something similar. Like I said: For each event of state$, the project function passed to state$.map is called twice.

@staltz
Copy link
Owner

staltz commented Aug 23, 2016

Interesting bug. It's definitely a bug, and definitely related to remember. But here's one interesting bit:

  return sourceTodosData$.map(sourceTodosData =>
    reducer$.fold((todosData, reducer) => reducer(todosData), sourceTodosData)
  ).flatten()
- .remember();

Removing that (in model()) fixes the issue, because then the debug('state') will also emit. The double emission is expected, it's app logic. The first emission is due to the fold seed, the second is due to changeRouteReducer$'s startWith.

Still, we need to fix remember() and MemoryStream.

@staltz
Copy link
Owner

staltz commented Oct 24, 2016

Fixed in v7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants