Skip to content

Commit cc5353f

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [v28] 44 pages modified
1 parent 4212b75 commit cc5353f

File tree

2 files changed

+63
-49
lines changed

2 files changed

+63
-49
lines changed

views/react.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ export const config = {
8888
actions
8989
}
9090

91-
export type Context = IContext<{
92-
state: typeof config.state
93-
actions: typeof config.actions
94-
}>
91+
export type Context = IContext<typeof config>
9592

9693
export const useAppState = createStateHook<Context>()
9794
export const useActions = createActionsHook<Context>()

views/vue.md

Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ There are three approaches to connecting Overmind to Vue.
1111
## Hooks \(experimental\)
1212

1313
{% tabs %}
14-
{% tab title="overmind/index.js" %}
14+
{% tab title="JavaScript" %}
1515
```typescript
16-
16+
// overmind/index.js
1717
import {
1818
createStateHook,
1919
createActionsHook,
@@ -37,12 +37,8 @@ export const hooks = {
3737
effects: createEffectsHook(),
3838
reaction: createReactionHook()
3939
}
40-
```
41-
{% endtab %}
4240

43-
{% tab title="index.js" %}
44-
```javascript
45-
import { createApp } from 'vue'
41+
// index.js
4642
import { createOvermind } from 'overmind'
4743
import { withOvermind } from 'overmind-vue/vu3'
4844
import { config } from './overmind'
@@ -53,11 +49,69 @@ const overmind = createOvermind(config)
5349
createApp(withOvermind(overmind, App)).mount('#app')
5450

5551
...
52+
53+
// components/SomeComponent.vue
54+
<template>
55+
<div @click="actions.onClick">
56+
{{ state.foo }}
57+
</div>
58+
</template>
59+
<script>
60+
import { hooks } from '../overmind'
61+
62+
export default {
63+
setup() {
64+
const state = hooks.state()
65+
const actions = hooks.actions()
66+
67+
return { state, actions }
68+
}
69+
}
70+
</script>
5671
```
5772
{% endtab %}
5873

59-
{% tab title="components/SomeComponent.vue" %}
74+
{% tab title="TypeScript" %}
6075
```javascript
76+
// overmind/index.ts
77+
import { IContext } from 'overmind'
78+
79+
import {
80+
createStateHook,
81+
createActionsHook,
82+
createEffectsHook,
83+
createReactionHook
84+
} from 'overmind-vue/vu3'
85+
import { state } from './state'
86+
import * as actions from './actions'
87+
88+
export const config = {
89+
state,
90+
actions
91+
}
92+
93+
export type Context = IContext<typeof config>
94+
95+
export const hooks = {
96+
state: createStateHook<Context>(),
97+
actions: createActionsHook<Context>(),
98+
effects: createEffectsHook<Context>(),
99+
reaction: createReactionHook<Context>()
100+
}
101+
102+
// index.ts
103+
import { createOvermind } from 'overmind'
104+
import { withOvermind } from 'overmind-vue/vu3'
105+
import { config } from './overmind'
106+
import App from './App.vue'
107+
108+
const overmind = createOvermind(config)
109+
110+
createApp(withOvermind(overmind, App)).mount('#app')
111+
112+
...
113+
114+
// components/SomeComponent.vue
61115
<template>
62116
<div @click="actions.onClick">
63117
{{ state.foo }}
@@ -153,43 +207,6 @@ If you prefer using JSX, that is also possible:
153207
{% endtab %}
154208
{% endtabs %}
155209

156-
With **TypeScript** you type them by:
157-
158-
{% tabs %}
159-
{% tab title="Typescript" %}
160-
```typescript
161-
// overmind/index.ts
162-
import { IContext } from 'overmind'
163-
164-
import {
165-
createStateHook,
166-
createActionsHook,
167-
createEffectsHook,
168-
createReactionHook
169-
} from 'overmind-vue/vu3'
170-
import { state } from './state'
171-
import * as actions from './actions'
172-
173-
export const config = {
174-
state,
175-
actions
176-
}
177-
178-
export type Context = IContext<{
179-
state: typeof config.state
180-
actions: typeof config.actions
181-
}>
182-
183-
export const hooks = {
184-
state: createStateHook<Context>(),
185-
actions: createActionsHook<Context>(),
186-
effects: createEffectsHook<Context>(),
187-
reaction: createReactionHook<Context>()
188-
}
189-
```
190-
{% endtab %}
191-
{% endtabs %}
192-
193210
## Plugin
194211

195212
Vue has a plugin system that allows us to expose Overmind to all components. This allows minimum configuration and you just use state etc. from any component.

0 commit comments

Comments
 (0)