Skip to content

Commit 634ee1c

Browse files
authored
docs(getting-started): Changes MST values to native Map.values in Getting Started tutorial (#1982 by @alexamy)
[skip ci]
1 parent 6a50d79 commit 634ee1c

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

docs/intro/getting-started.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,11 @@ MST loves MobX, and is fully compatible with it's `autorun`, `reaction`, `observ
328328

329329
```javascript
330330
import { observer } from 'mobx-react-lite'
331-
import { values } from 'mobx'
332331

333332
const App = observer(props => (
334333
<div>
335334
<button onClick={e => props.store.addTodo(randomId(), "New Task")}>Add Task</button>
336-
{values(props.store.todos).map(todo => (
335+
{Array.from(props.store.todos.values()).map(todo => (
337336
<div>
338337
<input type="checkbox" checked={todo.done} onChange={e => todo.toggle()} />
339338
<input type="text" value={todo.name} onChange={e => todo.setName(e.target.value)} />
@@ -366,7 +365,7 @@ const TodoView = observer(props => (
366365
const AppView = observer(props => (
367366
<div>
368367
<button onClick={e => props.store.addTodo(randomId(), "New Task")}>Add Task</button>
369-
{values(props.store.todos).map(todo => (
368+
{Array.from(props.store.todos.values()).map(todo => (
370369
<TodoView todo={todo} />
371370
))}
372371
</div>
@@ -391,10 +390,10 @@ const RootStore = types
391390
})
392391
.views(self => ({
393392
get pendingCount() {
394-
return values(self.todos).filter(todo => !todo.done).length
393+
return Array.from(self.todos.values()).filter(todo => !todo.done).length
395394
},
396395
get completedCount() {
397-
return values(self.todos).filter(todo => todo.done).length
396+
return Array.from(self.todos.values()).filter(todo => todo.done).length
398397
}
399398
}))
400399
.actions(self => ({
@@ -420,7 +419,7 @@ const TodoCounterView = observer(props => (
420419
const AppView = observer(props => (
421420
<div>
422421
<button onClick={e => props.store.addTodo(randomId(), "New Task")}>Add Task</button>
423-
{values(props.store.todos).map(todo => (
422+
{Array.from(props.store.todos.values()).map(todo => (
424423
<TodoView todo={todo} />
425424
))}
426425
<TodoCounterView store={props.store} />
@@ -446,13 +445,13 @@ const RootStore = types
446445
})
447446
.views(self => ({
448447
get pendingCount() {
449-
return values(self.todos).filter(todo => !todo.done).length
448+
return Array.from(self.todos.values()).filter(todo => !todo.done).length
450449
},
451450
get completedCount() {
452-
return values(self.todos).filter(todo => todo.done).length
451+
return Array.from(self.todos.values()).filter(todo => todo.done).length
453452
},
454453
getTodosWhereDoneIs(done) {
455-
return values(self.todos).filter(todo => todo.done === done)
454+
return Array.from(self.todos.values()).filter(todo => todo.done === done)
456455
}
457456
}))
458457
.actions(self => ({
@@ -613,7 +612,7 @@ Now we need to edit our views to display a select along with each `TodoView`, wh
613612
const UserPickerView = observer(props => (
614613
<select value={props.user ? props.user.id : ""} onChange={e => props.onChange(e.target.value)}>
615614
<option value="">-none-</option>
616-
{values(props.store.users).map(user => (
615+
{Array.from(props.store.users.values()).map(user => (
617616
<option value={user.id}>{user.name}</option>
618617
))}
619618
</select>
@@ -644,7 +643,7 @@ const TodoCounterView = observer(props => (
644643
const AppView = observer(props => (
645644
<div>
646645
<button onClick={e => props.store.addTodo(randomId(), "New Task")}>Add Task</button>
647-
{values(props.store.todos).map(todo => (
646+
{Array.from(props.store.todos.values()).map(todo => (
648647
<TodoView store={props.store} todo={todo} />
649648
))}
650649
<TodoCounterView store={props.store} />

0 commit comments

Comments
 (0)