diff options
Diffstat (limited to 'packages/main/src/infrastructure/electron/RendererBridge.ts')
-rw-r--r-- | packages/main/src/infrastructure/electron/RendererBridge.ts | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/packages/main/src/infrastructure/electron/RendererBridge.ts b/packages/main/src/infrastructure/electron/RendererBridge.ts index 3f9b512..097580a 100644 --- a/packages/main/src/infrastructure/electron/RendererBridge.ts +++ b/packages/main/src/infrastructure/electron/RendererBridge.ts | |||
@@ -22,16 +22,12 @@ import type { SharedStoreSnapshotOut } from '@sophie/shared'; | |||
22 | import { | 22 | import { |
23 | addMiddleware, | 23 | addMiddleware, |
24 | getSnapshot, | 24 | getSnapshot, |
25 | IJsonPatch, | 25 | type IJsonPatch, |
26 | IMiddlewareEvent, | ||
27 | onPatch, | 26 | onPatch, |
28 | } from 'mobx-state-tree'; | 27 | } from 'mobx-state-tree'; |
29 | 28 | ||
30 | import type MainStore from '../../stores/MainStore'; | 29 | import type MainStore from '../../stores/MainStore'; |
31 | import Disposer from '../../utils/Disposer'; | 30 | import Disposer from '../../utils/Disposer'; |
32 | import getLogger from '../../utils/getLogger'; | ||
33 | |||
34 | const log = getLogger('RendererBridge'); | ||
35 | 31 | ||
36 | export type PatchListener = (patch: IJsonPatch[]) => void; | 32 | export type PatchListener = (patch: IJsonPatch[]) => void; |
37 | 33 | ||
@@ -45,8 +41,6 @@ export default class RendererBridge { | |||
45 | constructor(store: MainStore, listener: PatchListener) { | 41 | constructor(store: MainStore, listener: PatchListener) { |
46 | this.snapshot = getSnapshot(store.shared); | 42 | this.snapshot = getSnapshot(store.shared); |
47 | 43 | ||
48 | // The call for the currently pending action, if any. | ||
49 | let topLevelCall: IMiddlewareEvent | undefined; | ||
50 | // An array of accumulated patches if we're in an action, `undefined` otherwise. | 44 | // An array of accumulated patches if we're in an action, `undefined` otherwise. |
51 | let patches: IJsonPatch[] | undefined; | 45 | let patches: IJsonPatch[] | undefined; |
52 | 46 | ||
@@ -63,25 +57,12 @@ export default class RendererBridge { | |||
63 | } | 57 | } |
64 | }); | 58 | }); |
65 | 59 | ||
66 | this.disposeMiddleware = addMiddleware(store, (call, next, abort) => { | 60 | this.disposeMiddleware = addMiddleware(store, (call, next) => { |
67 | if (call.parentActionEvent !== undefined) { | 61 | if (patches !== undefined) { |
68 | // We're already in an action, there's no need to enter one. | 62 | // We're already in an action, there's no need to enter one. |
69 | next(call); | 63 | next(call); |
70 | return; | 64 | return; |
71 | } | 65 | } |
72 | if (patches !== undefined) { | ||
73 | log.error( | ||
74 | 'Unexpected call', | ||
75 | call, | ||
76 | 'during dispatching another call', | ||
77 | topLevelCall, | ||
78 | 'with accumulated patches', | ||
79 | patches, | ||
80 | ); | ||
81 | abort(undefined); | ||
82 | return; | ||
83 | } | ||
84 | topLevelCall = call; | ||
85 | patches = []; | 66 | patches = []; |
86 | try { | 67 | try { |
87 | next(call); | 68 | next(call); |
@@ -91,7 +72,6 @@ export default class RendererBridge { | |||
91 | listener(patches); | 72 | listener(patches); |
92 | } | 73 | } |
93 | } finally { | 74 | } finally { |
94 | topLevelCall = undefined; | ||
95 | patches = undefined; | 75 | patches = undefined; |
96 | this.snapshot = getSnapshot(store.shared); | 76 | this.snapshot = getSnapshot(store.shared); |
97 | } | 77 | } |