gluon-framework / gluon

A new framework for creating desktop apps from websites, using system installed browsers and NodeJS
https://gluonjs.org
MIT License
3.1k stars 76 forks source link

RFC: IPC Store #32

Closed CanadaHonk closed 1 year ago

CanadaHonk commented 1 year ago

Proposal for adding a "Store" to IPC, accessible to both Node and Web, for easily sharing common data between them. Not persistent. Example usage:

Proposal 1 - Async getter/getter

Web would fetch config key from IPC when gotten, hence being async.

// Node backend
Window.ipc.store.config = {
  env: 'prod'
};
// Web frontend
const runningEnv = (await Gluon.ipc.store.config).env;

Proposal 2 - Sync getter/getter

Web would be sent updated Store key and values whenever they are set, hence being sync.

// Node backend
Window.ipc.store.config = {
  env: 'prod'
};
// Web frontend
const runningEnv = Gluon.ipc.store.config.env;

Proposal 3 - Async Functions

// Node backend
Window.ipc.store.set('config', {
  env: 'prod'
});
// Web frontend
const runningEnv = (await Gluon.ipc.store.get('config')).env;

Proposal 4 - Sync Functions

// Node backend
Window.ipc.store.set('config', {
  env: 'prod'
});
// Web frontend
const runningEnv = Gluon.ipc.store.get('config').env;

Please comment with which proposal(s), you prefer! Open to implementing 1/2 and 3/4.

yellowsink commented 1 year ago

My vote for 2

maisymoe commented 1 year ago

Same here, 2 is cleanest imo.

CamjamPNG commented 1 year ago

for anyone who doesn't understand the code here's what it is in English

image_2023-01-07_114535068

CanadaHonk commented 1 year ago

Proposals 2 and 4 were implemented in v0.11.0