Skip to content

Commit 41008f9

Browse files
docs(website): add angular stuff
1 parent 60ba002 commit 41008f9

File tree

18 files changed

+388
-44
lines changed

18 files changed

+388
-44
lines changed

packages/node_modules/overmind-angular/src/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import App, {
2-
ActionCallback,
3-
EventType,
4-
Configuration,
5-
TConfig,
6-
} from 'overmind'
1+
import App, { EventType, Configuration, TConfig } from 'overmind'
72

83
export * from 'overmind'
94

@@ -21,8 +16,6 @@ export type TConnect<App extends { state: any; actions: any }> = {
2116

2217
let nextComponentId = 0
2318

24-
let hasWarnedOnPush = false
25-
2619
export default class VueApp<
2720
Config extends Configuration,
2821
EvalConfig extends TConfig<Config>
@@ -36,13 +29,17 @@ export default class VueApp<
3629
const targetNgOnInit = target.prototype.ngOnInit
3730
const targetNgDoCheck = target.prototype.ngDoCheck
3831
const targetNgAfterViewChecked = target.prototype.ngAfterViewChecked
32+
const reactionFactory = instance.createReactionFactory(
33+
target.constructor.name
34+
)
3935
let currentTrackId
4036
let listener
4137

4238
target.prototype.ngOnInit = function() {
4339
this.app = {
4440
state: instance.state,
4541
actions: instance.actions,
42+
reaction: reactionFactory.add,
4643
}
4744
this.__componentInstanceId = componentInstanceId++
4845

packages/node_modules/overmind/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export { default as compute } from './computed'
99

1010
export { IValueAction, Compose }
1111

12+
export const log = (...objects: any[]) =>
13+
console.log(...objects.map((obj) => JSON.parse(JSON.stringify(obj))))
14+
1215
/*
1316
BASE TYPES
1417
*/
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Log
2+
3+
If you ever need to log out state it can be a good idea to use the log function from Overmind. First of all it will log out a plain value. Since Overmind heavily depends on JavaScript proxies a normal **console.log** will give you an object that you probably will not recognize at first sight. The other benefit of the Overmind logger is that it will show you the state of that value when it was logged. If you do a plain **console.log** on an object or array your developer console will show you the latest state of the value, meaning that it might have changed after you logged. This can be very confusing when debugging.
4+
5+
```marksy
6+
h(Example, {name: "api/log"})
7+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const js = [
2+
{
3+
fileName: 'app/mutations.js',
4+
code: `
5+
import { log } from 'overmind'
6+
7+
export const setItems = (state, items) => {
8+
log(state.items)
9+
state.items = items
10+
}
11+
`,
12+
},
13+
]
14+
15+
export const ts = [
16+
{
17+
fileName: 'app/mutations.ts',
18+
code: `
19+
import { Mutation, log } from 'overmind'
20+
import { Item } from './state'
21+
22+
export const setItems: Mutation<Item[]> = (state, items) => {
23+
log(state.items)
24+
state.items = items
25+
}
26+
`,
27+
},
28+
]

packages/overmind-website/examples/guide/connectingcomponents/actions.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ export const toggleAwesomeApp: Action = action =>
6767
`,
6868
},
6969
{
70-
fileName: 'components/List.vue (template)',
70+
fileName: 'components/App.vue (template)',
7171
target: 'markup',
7272
code: `
73-
<h1>{{app.state.myObject}}</h1>
73+
<button v-on:click="app.actions.toggleAwesomeApp()">
74+
Toggle awesome
75+
</button>
7476
`,
7577
},
7678
{
77-
fileName: 'components/List.vue (script)',
79+
fileName: 'components/App.vue (script)',
7880
code: `
7981
import app from './app'
8082
@@ -84,3 +86,41 @@ export default app.connect({})
8486
]
8587

8688
export const vueTs = vue
89+
90+
export const angularTs = [
91+
{
92+
fileName: 'app/actions.ts',
93+
code: `
94+
import * as mutations from './mutations'
95+
96+
export const toggleAwesomeApp: Action = action =>
97+
action()
98+
.mutate(mutations.toggleAwesomeApp)
99+
`,
100+
},
101+
{
102+
fileName: 'components/app.component.ts',
103+
code: `
104+
import {
105+
Component,
106+
ChangeDetectionStrategy,
107+
ChangeDetectorRef
108+
} from '@angular/core';
109+
import app from '../app'
110+
111+
@Component({
112+
selector: 'app-root',
113+
changeDetection: ChangeDetectionStrategy.OnPush,
114+
template: \`
115+
<button (click)="app.actions.toggleAwesomeApp()">
116+
Toggle awesome
117+
</button>
118+
\`
119+
})
120+
@app.connect()
121+
export class App {
122+
constructor(private cdr: ChangeDetectorRef) {}
123+
}
124+
`,
125+
},
126+
]

packages/overmind-website/examples/guide/connectingcomponents/array_1.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react'
77
import app from './app'
88
99
const List = ({ app }) => (
10-
<h1>{app.state.myArray}</h1>
10+
<h1>{app.state.items}</h1>
1111
)
1212
1313
export default app.connect(List)
@@ -23,7 +23,7 @@ import * as React from 'react'
2323
import app, { Connect } from './app'
2424
2525
const List: React.SFC<Connect> = ({ app }) => (
26-
<h1>{app.state.myArray}</h1>
26+
<h1>{app.state.items}</h1>
2727
)
2828
2929
export default app.connect(List)
@@ -36,7 +36,7 @@ export const vue = [
3636
fileName: 'components/List.vue (template)',
3737
target: 'markup',
3838
code: `
39-
<h1>{{app.state.myArray}}</h1>
39+
<h1>{{app.state.items}}</h1>
4040
`,
4141
},
4242
{
@@ -50,3 +50,29 @@ export default app.connect({})
5050
]
5151

5252
export const vueTs = vue
53+
54+
export const angularTs = [
55+
{
56+
fileName: 'components/list.component.ts',
57+
code: `
58+
import {
59+
Component,
60+
ChangeDetectionStrategy,
61+
ChangeDetectorRef
62+
} from '@angular/core';
63+
import app from '../app'
64+
65+
@Component({
66+
selector: 'app-list',
67+
changeDetection: ChangeDetectionStrategy.OnPush,
68+
template: \`
69+
<h1>{{app.state.items}}</h1>
70+
\`
71+
})
72+
@app.connect()
73+
export class List {
74+
constructor(private cdr: ChangeDetectorRef) {}
75+
}
76+
`,
77+
},
78+
]

packages/overmind-website/examples/guide/connectingcomponents/array_2.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import app from './app'
88
99
const List = ({ app }) => (
1010
<ul>
11-
{app.state.myArray.map(item =>
11+
{app.state.items.map(item =>
1212
<li key={item.id}>{item.title}</li>
1313
)}
1414
</ul>
@@ -28,7 +28,7 @@ import app, { Connect } from './app'
2828
2929
const List: React.SFC<Connect> = ({ app }) => (
3030
<ul>
31-
{app.state.myArray.map(item =>
31+
{app.state.items.map(item =>
3232
<li key={item.id}>{item.title}</li>
3333
)}
3434
</ul>
@@ -45,7 +45,7 @@ export const vue = [
4545
target: 'markup',
4646
code: `
4747
<ul>
48-
<li v-for="item in app.state.myArray" :key="item.id>
48+
<li v-for="item in app.state.items" :key="item.id>
4949
{{ item.title }}
5050
</li>
5151
</ul>
@@ -62,3 +62,36 @@ export default app.connect({})
6262
]
6363

6464
export const vueTs = vue
65+
66+
export const angularTs = [
67+
{
68+
fileName: 'components/list.component.ts',
69+
code: `
70+
import {
71+
Component,
72+
ChangeDetectionStrategy,
73+
ChangeDetectorRef
74+
} from '@angular/core';
75+
import app from '../app'
76+
77+
@Component({
78+
selector: 'app-list',
79+
changeDetection: ChangeDetectionStrategy.OnPush,
80+
template: \`
81+
<ul>
82+
<li *ngFor="let item of app.state.items;trackby: trackById">
83+
{{item.title}}
84+
</li>
85+
</ul>
86+
\`
87+
})
88+
@app.connect()
89+
export class List {
90+
constructor(private cdr: ChangeDetectorRef) {}
91+
trackById(index, item) {
92+
return item.id
93+
}
94+
}
95+
`,
96+
},
97+
]

packages/overmind-website/examples/guide/connectingcomponents/array_3.ts

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Item from './Item'
2323
2424
const App = ({ app }) => (
2525
<ul>
26-
{app.state.myArray.map(item =>
26+
{app.state.items.map(item =>
2727
<Item key={item.id} item={item} />
2828
)}
2929
</ul>
@@ -61,7 +61,7 @@ import Item from './Item'
6161
6262
const List: React.SFC<Connect> = ({ app }) => (
6363
<ul>
64-
{app.state.myArray.map(item =>
64+
{app.state.items.map(item =>
6565
<Item key={item.id} item={item} />
6666
)}
6767
</ul>
@@ -95,7 +95,7 @@ export default app.connect({
9595
target: 'markup',
9696
code: `
9797
<ul>
98-
<li is="Item" v-for="item in app.state.myArray" v-bind:item="item" :key="item.id" />
98+
<li is="Item" v-for="item in app.state.items" v-bind:item="item" :key="item.id" />
9999
</ul>
100100
`,
101101
},
@@ -115,3 +115,65 @@ export default app.connect({
115115
]
116116

117117
export const vueTs = vue
118+
119+
export const angularTs = [
120+
{
121+
fileName: 'components/item.component.ts',
122+
code: `
123+
import {
124+
Component,
125+
ChangeDetectionStrategy,
126+
ChangeDetectorRef,
127+
Input
128+
} from '@angular/core';
129+
import app from '../app'
130+
import { Item } from '../app/state'
131+
132+
@Component({
133+
selector: 'app-list-item',
134+
changeDetection: ChangeDetectionStrategy.OnPush,
135+
template: \`
136+
<li>
137+
{{item.title}}
138+
</li>
139+
\`
140+
})
141+
@app.connect()
142+
export class List {
143+
@Input() item: Item;
144+
constructor(private cdr: ChangeDetectorRef) {}
145+
}
146+
`,
147+
},
148+
{
149+
fileName: 'components/list.component.ts',
150+
code: `
151+
import {
152+
Component,
153+
ChangeDetectionStrategy,
154+
ChangeDetectorRef
155+
} from '@angular/core';
156+
import app from '../app'
157+
158+
@Component({
159+
selector: 'app-list',
160+
changeDetection: ChangeDetectionStrategy.OnPush,
161+
template: \`
162+
<ul>
163+
<app-list-item
164+
*ngFor="let item of app.state.items;trackby: trackById"
165+
[item]="item"
166+
></app-list-item>
167+
</ul>
168+
\`
169+
})
170+
@app.connect()
171+
export class List {
172+
constructor(private cdr: ChangeDetectorRef) {}
173+
trackById(index, item) {
174+
return item.id
175+
}
176+
}
177+
`,
178+
},
179+
]

0 commit comments

Comments
 (0)