You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// We do not need zones, we rather use the tracking
88
+
// directive, which gives us a huge optimization
89
+
ngZone: "noop"
90
+
})
91
+
.catch(err=>console.log(err));
92
+
93
+
```
94
+
{% endtab %}
72
95
{% endtabs %}
73
96
74
97
The **service** is responsible for exposing the configuration of your application. The **\*track** directive is what does the actual tracking. Just put it at the top of your template and whatever state you access will be optimally tracked. You can also select a namespace from your state to expose to the component:
Copy file name to clipboardExpand all lines: guides-1/managing-lists.md
+32-4Lines changed: 32 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,23 @@ But we still want to use an array when we transform the state into a UI. Let us
29
29
In Overmind it is encouraged that you derive these dictionaries of entities to a list by deriving the state. The most simple way to do this is:
30
30
31
31
{% tabs %}
32
-
{% tab title="overmind/state.js" %}
32
+
{% tab title="overmind/state.ts" %}
33
33
```typescript
34
-
exportconst state = {
34
+
import { Derive } from'overmind'
35
+
36
+
exporttypePost {
37
+
id: string
38
+
title: string
39
+
body: string
40
+
datetime: number
41
+
}
42
+
43
+
exporttypeState= {
44
+
posts: { [id:string] :Post }
45
+
postsList:Derive<State, Post[]>
46
+
}
47
+
48
+
exportconst state:State= {
35
49
posts: {}
36
50
postsList: state=>Object.values(state.posts)
37
51
}
@@ -46,9 +60,23 @@ Now when we point to **state.postsList** we get an array of posts. What is impor
46
60
Now we have optimally stored our posts in a dictionary for easy access by id. We have also created a derived state which converts this dictionary to an array whenever the source dictionary changes. Though most likely you want to sort the list. Typically lists are sorted chronologically and our posts item has a **datetime** field.
0 commit comments