Skip to content

Commit

Permalink
Issue #590 (#591)
Browse files Browse the repository at this point in the history
* Removed MobX Todos unused observable #529

* updated example code with latest json_serializable

* synced todo list example docs with latest code
  • Loading branch information
pr-1 committed Nov 2, 2020
1 parent becd68e commit 40520a5
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 186 deletions.
24 changes: 4 additions & 20 deletions docs/docs/examples/todos/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Next comes the `TodoList`, which manages a list of `Todo`s. The core-state of `T

- [x] a list of `Todo`s
- [x] a `filter` that tracks the visibility-filter applied on the list of todos
- [x] the `currentDescription`, which tracks the description entered by the user for a new todo.


This can be seen with the `@observable` properties.

Expand All @@ -66,9 +66,6 @@ abstract class _TodoList with Store {
@observable
VisibilityFilter filter = VisibilityFilter.all;
@observable
String currentDescription = '';
}
```

Expand Down Expand Up @@ -149,17 +146,14 @@ abstract class _TodoList with Store {
void addTodo(String description) {
final todo = Todo(description);
todos.add(todo);
currentDescription = '';
}
@action
void removeTodo(Todo todo) {
todos.removeWhere((x) => x == todo);
}
@action
void changeDescription(String description) =>
currentDescription = description;
@action
void changeFilter(VisibilityFilter filter) => this.filter = filter;
Expand Down Expand Up @@ -194,9 +188,6 @@ abstract class _TodoList with Store {
@observable
VisibilityFilter filter = VisibilityFilter.all;
@observable
String currentDescription = '';
@computed
ObservableList<Todo> get pendingTodos =>
ObservableList.of(todos.where((todo) => todo.done != true));
Expand Down Expand Up @@ -245,18 +236,13 @@ abstract class _TodoList with Store {
void addTodo(String description) {
final todo = Todo(description);
todos.add(todo);
currentDescription = '';
}
@action
void removeTodo(Todo todo) {
todos.removeWhere((x) => x == todo);
}
@action
void changeDescription(String description) =>
currentDescription = description;
@action
void changeFilter(VisibilityFilter filter) => this.filter = filter;
Expand Down Expand Up @@ -380,7 +366,7 @@ class TodoListView extends StatelessWidget {

**AddTodo**

Similarly, here is the `AddTodo` widget that observes the `list.currentDescription` and also fires the `list.changeDescription` action.
Similarly, here is the `AddTodo` widget that fires the `list.addTodo` action.

```dart
class AddTodo extends StatelessWidget {
Expand All @@ -395,9 +381,7 @@ class AddTodo extends StatelessWidget {
decoration: const InputDecoration(
labelText: 'Add a Todo', contentPadding: EdgeInsets.all(8)),
controller: _textController,
onChanged: (String newValue) {
list.currentDescription = newValue;
},
textInputAction: TextInputAction.done,
onSubmitted: (String value) {
list.addTodo(value);
_textController.clear();
Expand Down
Loading

0 comments on commit 40520a5

Please sign in to comment.