aboutsummaryrefslogtreecommitdiffstats
path: root/packages/preload/src/contextBridge/SophieRendererImpl.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-27 02:24:22 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-12-27 02:37:38 +0100
commit11cf57ce92aff4dcdb504194ea5c381ac400c5c5 (patch)
tree2fb6fbc28903d61d1a79f2cf95753d8b83eaf4e4 /packages/preload/src/contextBridge/SophieRendererImpl.ts
parenttest: Add preload unit tests (diff)
downloadsophie-11cf57ce92aff4dcdb504194ea5c381ac400c5c5.tar.gz
sophie-11cf57ce92aff4dcdb504194ea5c381ac400c5c5.tar.zst
sophie-11cf57ce92aff4dcdb504194ea5c381ac400c5c5.zip
refactor: Simplify IpcRendererService and its spec
Diffstat (limited to 'packages/preload/src/contextBridge/SophieRendererImpl.ts')
-rw-r--r--packages/preload/src/contextBridge/SophieRendererImpl.ts13
1 files changed, 8 insertions, 5 deletions
diff --git a/packages/preload/src/contextBridge/SophieRendererImpl.ts b/packages/preload/src/contextBridge/SophieRendererImpl.ts
index 61b01e9..bbb4f65 100644
--- a/packages/preload/src/contextBridge/SophieRendererImpl.ts
+++ b/packages/preload/src/contextBridge/SophieRendererImpl.ts
@@ -27,16 +27,17 @@ import {
27 SophieRenderer, 27 SophieRenderer,
28} from '@sophie/shared'; 28} from '@sophie/shared';
29 29
30import { RendererToMainIpcService } from '../services/RendererToMainIpcService'; 30import { IpcRendererService } from '../services/IpcRendererService';
31 31
32class SophieRendererImpl implements SophieRenderer { 32class SophieRendererImpl implements SophieRenderer {
33 readonly #ipcService = new RendererToMainIpcService(); 33 readonly #ipcService;
34 34
35 #onSharedStoreChangeCalled: boolean = false; 35 #onSharedStoreChangeCalled: boolean = false;
36 36
37 #listener: SharedStoreListener | null = null; 37 #listener: SharedStoreListener | null = null;
38 38
39 constructor() { 39 constructor(ipcService: IpcRendererService) {
40 this.#ipcService = ipcService;
40 this.#ipcService.onSharedStorePatch((patch) => { 41 this.#ipcService.onSharedStorePatch((patch) => {
41 try { 42 try {
42 // `mobx-state-tree` will validate the patch, so we can safely cast here. 43 // `mobx-state-tree` will validate the patch, so we can safely cast here.
@@ -87,8 +88,10 @@ class SophieRendererImpl implements SophieRenderer {
87 } 88 }
88} 89}
89 90
90export function createSophieRenderer(): SophieRenderer { 91export function createSophieRenderer(
91 const impl = new SophieRendererImpl(); 92 ipcService: IpcRendererService,
93): SophieRenderer {
94 const impl = new SophieRendererImpl(ipcService);
92 return { 95 return {
93 onSharedStoreChange: impl.onSharedStoreChange.bind(impl), 96 onSharedStoreChange: impl.onSharedStoreChange.bind(impl),
94 dispatchAction: impl.dispatchAction.bind(impl), 97 dispatchAction: impl.dispatchAction.bind(impl),