Skip to content

Commit 9468c1e

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [master] 2 pages modified
1 parent e01fa2e commit 9468c1e

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

addons/angular.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,29 @@ export class AppComponent {
6969
}
7070
```
7171
{% endtab %}
72+
73+
{% tab title="main.ts" %}
74+
```typescript
75+
import { enableProdMode } from "@angular/core";
76+
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
77+
78+
import { AppModule } from "./app/app.module";
79+
import { environment } from "./environments/environment";
80+
81+
if (environment.production) {
82+
enableProdMode();
83+
}
84+
85+
platformBrowserDynamic()
86+
.bootstrapModule(AppModule, {
87+
// 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 %}
7295
{% endtabs %}
7396

7497
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:

guides-1/managing-lists.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,23 @@ But we still want to use an array when we transform the state into a UI. Let us
2929
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:
3030

3131
{% tabs %}
32-
{% tab title="overmind/state.js" %}
32+
{% tab title="overmind/state.ts" %}
3333
```typescript
34-
export const state = {
34+
import { Derive } from 'overmind'
35+
36+
export type Post {
37+
id: string
38+
title: string
39+
body: string
40+
datetime: number
41+
}
42+
43+
export type State = {
44+
posts: { [id: string] : Post }
45+
postsList: Derive<State, Post[]>
46+
}
47+
48+
export const state: State = {
3549
posts: {}
3650
postsList: state => Object.values(state.posts)
3751
}
@@ -46,9 +60,23 @@ Now when we point to **state.postsList** we get an array of posts. What is impor
4660
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.
4761

4862
{% tabs %}
49-
{% tab title="overmind/state.js" %}
63+
{% tab title="overmind/state.ts" %}
5064
```typescript
51-
export const state = {
65+
import { Derive } from 'overmind'
66+
67+
export type Post {
68+
id: string
69+
title: string
70+
body: string
71+
datetime: number
72+
}
73+
74+
export type State = {
75+
posts: { [id: string] : Post }
76+
postsList: Derive<State, Post[]>
77+
}
78+
79+
export const state: State = {
5280
posts: {}
5381
postsList: state =>
5482
Object.values(state.posts)

0 commit comments

Comments
 (0)