Skip to content

Commit 950e063

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [master] 2 pages modified
1 parent 566c2ac commit 950e063

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

core/defining-state.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ export const state = {
113113
{% endtab %}
114114
{% endtabs %}
115115

116-
{% hint style="warning" %}
117-
It is import that you do **NOT** use arrow functions on your methods. The reason is that this binds the context of the method to the instance itself, meaning that Overmind is unable to proxy access and allow you to do tracked mutations
118-
{% endhint %}
119-
120116
You can now use this instance as normal and of course create new ones.
121117

122118
{% hint style="info" %}

core/running-side-effects.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,35 @@ export const onInitialize = async ({ effects }) => {
132132
Typically you explicitly communicate with effects from actions, by calling methods. But sometimes you need effects to know about the state of the application, or maybe some internal state in the effect should be exposed on your application state. Again we can take advantage of an **initialize** method on the effect:
133133

134134
{% tabs %}
135+
{% tab title="overmind/effects.js" %}
136+
```javascript
137+
// We use an IIFE to isolate some variables
138+
export const socket = (() => {
139+
_options
140+
_ws
141+
return {
142+
initialize(options) {
143+
_options = options
144+
_ws = new WebSocket('ws://...')
145+
_ws.onclose = () => options.onStatusChange('close')
146+
_ws.onopen = () => options.onStatusChange('open')
147+
_ws.addEventListener(
148+
'message',
149+
(event) => options.onMessage(event.data)
150+
)
151+
},
152+
send(type, data) {
153+
_ws.postMessage({
154+
type,
155+
data,
156+
token: _options.getToken()
157+
})
158+
}
159+
}
160+
})()
161+
```
162+
{% endtab %}
163+
135164
{% tab title="overmind/onInitialize.js" %}
136165
```typescript
137166
export const onInitialize = async ({ state, effects, actions }) => {

0 commit comments

Comments
 (0)