Skip to content

Commit 2d83a26

Browse files
fix(overmind): ensure reconnect and backwards delimiter compatability
1 parent 62325e6 commit 2d83a26

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

packages/node_modules/overmind-devtools-client/src/BackendConnector.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class WebsocketConnector {
2727
if (this.socket) {
2828
reject(new Error('TODO: Socked already open, what now?'))
2929
}
30-
3130
this.socket = new WebSocket(`ws://localhost:${port}?devtools=1`)
3231
this.socket.onmessage = (message) => {
3332
const parsedMessage = JSON.parse(message.data)
@@ -49,12 +48,7 @@ class WebsocketConnector {
4948
}
5049
this.socket.onclose = (reason) => {
5150
console.log("Socket closed", reason)
52-
alert("The client lost connection to the backend, we have no idea why. Please report this if it occurs. We will now restart the application")
53-
// @ts-ignore
54-
if (window.onRestart) {
55-
// @ts-ignore
56-
window.onRestart()
57-
}
51+
setTimeout(() => this.connect(port), 1000)
5852
}
5953
})
6054
}

packages/node_modules/overmind-devtools-client/src/components/History/styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { css } from 'emotion'
2+
23
import { colors } from '../../theme'
34

45
export const wrapper = css({
56
padding: '2rem',
6-
height: '100%',
7+
height: '100vh',
78
boxSizing: 'border-box',
89
overflowY: 'scroll',
910
fontSize: 14,

packages/node_modules/overmind-devtools-client/src/overmind/operators.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const runGetterMutation: () => Operator<GetterMessage> = () =>
4949
method: 'set',
5050
path: message.data.path,
5151
args: [message.data.value],
52+
delimiter: state.apps[message.appName].delimiter || '.'
5253
})
5354
})
5455

@@ -155,12 +156,14 @@ export const removeComponent: () => Operator<RemoveComponentMessage> = () =>
155156
export const updateDerived: () => Operator<DerivedMessage> = () =>
156157
mutate(({ state }, message) => {
157158
const appState = state.apps[message.appName].state
158-
const path = message.data.path.slice()
159+
// For backwards compatability it can still be a string
160+
const actualPath = Array.isArray(message.data.path) ? message.data.path : (message.data.path as any).split('.')
161+
const path = actualPath.slice()
159162
const key = path.pop()
160163
const target = path.reduce((aggr, pathKey) => aggr[pathKey], appState)
161164
target[key] = message.data.value
162165

163-
state.apps[message.appName].derived[message.data.path.join(state.apps[message.appName].delimiter)] = message.data
166+
state.apps[message.appName].derived[actualPath.join(state.apps[message.appName].delimiter)] = message.data
164167
})
165168

166169
export const updateFlushWithDerived: () => Operator<DirtyDerivedMessage> = () =>
@@ -301,6 +304,12 @@ export const updateAction: () => Operator<EndActionMessage> = () =>
301304
export const addMutations: () => Operator<MutationsMessage> = () =>
302305
mutate(({ state }, message) => {
303306
const mutations = message.data
307+
308+
// For backwards compatability, ensure delimiter
309+
mutations.mutations.forEach((mutation) => {
310+
mutation.delimiter = mutation.delimiter || '.'
311+
})
312+
304313
const id = `${mutations.actionId}_${mutations.executionId}`
305314
const operator =
306315
state.apps[message.appName].actions[id].operators[mutations.operatorId]

packages/node_modules/overmind-devtools-client/src/overmind/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export type Mutation = {
22
args: any[]
33
method: string
44
path: string
5+
delimiter: string
56
}
67

78
export type OperatorsByPath = Array<{

packages/node_modules/overmind-devtools-client/src/overmind/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as ColorHash from 'color-hash'
22

3-
import { Action, App, Flush, OperatorsByPath } from './types'
3+
import { Action, App, Flush, Mutation, OperatorsByPath } from './types'
44

5-
export const runMutation = (state) => (mutation) => {
5+
export const runMutation = (state) => (mutation: Mutation) => {
66
const pathArray = mutation.path.split(mutation.delimiter)
77
const key = pathArray.pop()
88
const target = pathArray.reduce((current, pathKey) => current[pathKey].__CLASS__ ? current[pathKey].value : current[pathKey], state)

0 commit comments

Comments
 (0)