From 9900ac4be59aa8ab32aad28a4a3da214dc8dc196 Mon Sep 17 00:00:00 2001 From: Attila Gazso <230163+agazso@users.noreply.github.com> Date: Fri, 8 Sep 2023 16:28:59 +0200 Subject: [PATCH] wip: generic WakuObject types --- src/lib/objects/external/iframe.svelte | 15 +++++++++++++- src/lib/objects/index.d.ts | 27 +++++++++++++++++++------- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/lib/objects/external/iframe.svelte b/src/lib/objects/external/iframe.svelte index b0fa90bf..7adcdc4c 100644 --- a/src/lib/objects/external/iframe.svelte +++ b/src/lib/objects/external/iframe.svelte @@ -84,11 +84,23 @@ } function updateContext(force = false) { - const { chatId, objectId, instanceId, profile, users, tokens, view, store } = args + const { + chatId, + chatName, + objectId, + instanceId, + profile, + users, + tokens, + view, + viewParams, + store, + } = args const iframeContextChange: IframeContextChange = { type: 'iframe-context-change', state: { chatId, + chatName, objectId, instanceId, profile, @@ -97,6 +109,7 @@ }, context: { view, + viewParams, store, }, } diff --git a/src/lib/objects/index.d.ts b/src/lib/objects/index.d.ts index 882203a3..24472dd4 100644 --- a/src/lib/objects/index.d.ts +++ b/src/lib/objects/index.d.ts @@ -36,24 +36,33 @@ export interface WakuObjectState { type StoreType = JSONSerializable type DataMessageType = JSONSerializable -export interface WakuObjectContextProps { +export interface WakuObjectContextProps< + StoreType = JSONSerializable, + ViewType extends string = string, +> { readonly store?: StoreType readonly view?: ViewType + readonly viewParams: string[] // Other path params after the screen } -export interface WakuObjectContext extends WakuObjectContextProps, WakuObjectAdapter { +export interface WakuObjectContext< + StoreType = JSONSerializable, + DataMessageType = JSONSerializable, + ViewType extends string = string, +> extends WakuObjectContextProps, + WakuObjectAdapter { updateStore: (updater: (state?: StoreType) => StoreType) => void send: (data: DataMessageType) => Promise - readonly view?: ViewType // Screen to show on Waku object - readonly viewParams: string[] // Other path params after the screen onViewChange: (view: ViewType, ...rest: string[]) => void } export interface WakuObjectArgs< + StoreType = JSONSerializable, + DataMessageType = JSONSerializable, ViewType extends string = string, -> extends WakuObjectContext, +> extends WakuObjectContext, WakuObjectState {} interface WakuObjectMetadata { @@ -64,17 +73,21 @@ interface WakuObjectMetadata { } interface WakuObjectDescriptor< + StoreType = JSONSerializable, + DataMessageType = JSONSerializable, ViewType extends string = string, > extends WakuObjectMetadata { onMessage?: ( message: DataMessage, - args: WakuObjectArgs, + args: WakuObjectArgs, ) => Promise } interface WakuObjectSvelteDescriptor< + StoreType = JSONSerializable, + DataMessageType = JSONSerializable, ViewType extends string = string, -> extends WakuObjectDescriptor { +> extends WakuObjectDescriptor { readonly wakuObject: ComponentType readonly standalone?: ComponentType }