Mobx-state-tree: map.values() in getting started

Created on 25 Apr 2018  路  5Comments  路  Source: mobxjs/mobx-state-tree

Hey guys,

Quite a newbie so I might be doing something wrong. I wasn't able to get the getting started
tutorial working without spreading the map.values() being used:

[ ...store.todos.values() ].map(todo => <TodoView todo={todo} /> )

Not sure if I am missing something here?

Cheers,

Vincent

bug has PR

Most helpful comment

I think .values() returns now a generator. You can use either Array.from(store.todos.values()) or import values from the mobx package and use values(store.todos).

By the way, is this info wrong somewhere in the getting started tutorial? If so, could you please point us where so we can fix it?
EDIT: No problem, I found it 馃槃

All 5 comments

I think .values() returns now a generator. You can use either Array.from(store.todos.values()) or import values from the mobx package and use values(store.todos).

By the way, is this info wrong somewhere in the getting started tutorial? If so, could you please point us where so we can fix it?
EDIT: No problem, I found it 馃槃

quick fyi, I tried both of @luisherranz 's suggestions and they both work for me in code sandbox - I don't suppose there's any guidance on one being better than the other? or does it just come down to personal preference?

the first of the suggested methods:
Array.from(props.store.todos.values())
and that worked, minus an eslint error on Code Sandbox

when I tried the second method:
values(props.store.todos)
it worked as well without eslint error on Code Sandbox

get the same error from the next code item, Computed Properties and was able to fix it in my own code by using the
get pendingCount() { return values(self.todos).filter(todo => !todo.done).length },
is this an acceptable use of 'values' ? will it still be computed properly or should I try a different tack?

I can take a first swipe at a PR for updating information in the getting-started guide once the above PR is accepted if that'd be helpful?

is this an acceptable use of 'values' ? will it still be computed properly or should I try a different tack?

Absolutely!

values() is now the recommended approach. I changed the docs and the codesandbox. You can take a look at the PR here: https://github.com/mobxjs/mobx-state-tree/pull/784

Closing now. Feel free to reopen if needed!

It can also be traced in the videos uploaded on youtube here

Was this page helpful?
0 / 5 - 0 ratings