
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@den59k/electron-sync
Advanced tools
The library is provided to synchronize data between the main process and the renderer
Yeah, it is supports batching. All sync process exec in nextTick
Code splited on 3 parts. For better performance you should import files from subdirectories.
Main containts methods for main process
import { syncMain, proxyMethods } from '@den59k/electron-sync/lib/main'
syncMain
is responsible for data synchronization, and proxyMethods
is the pretty wrapper for ipcRenderer
For data:
import { syncMain } from "@den59k/electron-sync/lib/main"
class CounterData {
value = 1
}
const counterData = syncMain(new CounterData(), [ "counter" ])
export { counterData, CounterData }
For methods:
import { proxyMethods } from '@den59k/electron-sync/lib/main'
import { counterData } from '../data/counter'
class CounterService {
constructor() {
proxyMethods(this, "counter")
}
increment() {
counterData.value++
}
}
export const counterService = new CounterService()
Renderer containts methods for renderer process
import { syncRenderer } from '@den59k/electron-sync/lib/renderer'
const data = syncRenderer('counter', (obj: CounterData) => reactive(obj))
If you are using React and Mobx, you can set the action wrapper for all sync calls:
import { action } from 'mobx'
import { setActionWrapper } from '@den59k/electron-sync/lib/renderer'
setActionWrapper(action)
And finally, scripts for preload
import { bridge, proxy } from '@den59k/electron-sync/lib/preload'
As mentioned before, proxyMethods provides a pretty wrapper for the ipcRenderer->ipcMain channel.
To use it, you need to list the proxied methods in the preloader:
First the methods that do not expect anything ipcRenderer.send
Then methods that call promis and expect its result ipcRenderer.invoke
And finally, methods which call synchronously and expect a synchronous response ipcRenderer.sendSync
.
P.S. Sorry about the dummy second argument hack. It is necessary because typescript does not allow to make partial generic types
const electronBridge = {
...bridge,
counter: counter: proxy("counter", {} as typeof counterService, [ "increment" ], [], []))
}
contextBridge.exposeInMainWorld('electron', electronBridge)
FAQs
Syncronize store between main and renderer processes
The npm package @den59k/electron-sync receives a total of 4 weekly downloads. As such, @den59k/electron-sync popularity was classified as not popular.
We found that @den59k/electron-sync demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.