Store settings in lowdb

This commit is contained in:
Thomas Nordquist
2019-02-17 17:05:12 +01:00
parent 1740df6218
commit 3f52944f18
9 changed files with 194 additions and 22 deletions

View File

@@ -21,10 +21,11 @@ class IpcMainEventBus implements EventBusInterface {
this.ipc = ipc
}
public subscribe<MessageType>(event: Event<MessageType>, callback:(msg: MessageType) => void) {
console.log('subscribing', event.topic)
this.ipc.on(event.topic, (event: any, arg: any) => {
public subscribe<MessageType>(subscribeEvent: Event<MessageType>, callback:(msg: MessageType) => void) {
console.log('subscribing', subscribeEvent.topic)
this.ipc.on(subscribeEvent.topic, (event: any, arg: any) => {
this.client = event.sender
console.log(subscribeEvent.topic, arg)
callback(arg)
})
}

38
events/StorageEvents.ts Normal file
View File

@@ -0,0 +1,38 @@
import { Event } from './'
interface StorageEvent {
transactionId: string
}
export interface StoreCommand extends StorageEvent {
store: string,
data: any
}
export interface LoadCommand extends StorageEvent {
store: string,
}
export const storageStoreEvent: Event<StoreCommand> = {
topic: 'storage/store',
}
export const storageLoadEvent: Event<LoadCommand> = {
topic: 'storage/load',
}
export function makeStorageAcknoledgementEvent(transactionId: string): Event<StoreCommand> {
return {
topic: `storage/ack/${transactionId}`,
}
}
export function makeStorageResponseEvent(transactionId: string): Event<StoreCommand> {
return {
topic: `storage/response/${transactionId}`,
}
}
export const storageClearEvent: Event<StorageEvent> = {
topic: 'storage/clear',
}