Skip to content

Commit

Permalink
wip: generic WakuObject types
Browse files Browse the repository at this point in the history
  • Loading branch information
agazso committed Sep 8, 2023
1 parent 4ca57f2 commit 9900ac4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
15 changes: 14 additions & 1 deletion src/lib/objects/external/iframe.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -97,6 +109,7 @@
},
context: {
view,
viewParams,
store,
},
}
Expand Down
27 changes: 20 additions & 7 deletions src/lib/objects/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,33 @@ export interface WakuObjectState {
type StoreType = JSONSerializable
type DataMessageType = JSONSerializable

export interface WakuObjectContextProps<ViewType extends string = string> {
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<ViewType extends string = string> extends WakuObjectContextProps<ViewType>, WakuObjectAdapter {
export interface WakuObjectContext<
StoreType = JSONSerializable,
DataMessageType = JSONSerializable,
ViewType extends string = string,
> extends WakuObjectContextProps<StoreType, ViewType>,
WakuObjectAdapter {
updateStore: (updater: (state?: StoreType) => StoreType) => void

send: (data: DataMessageType) => Promise<void>

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<ViewType>,
> extends WakuObjectContext<StoreType, DataMessageType, ViewType>,
WakuObjectState {}

interface WakuObjectMetadata {
Expand All @@ -64,17 +73,21 @@ interface WakuObjectMetadata {
}

interface WakuObjectDescriptor<
StoreType = JSONSerializable,
DataMessageType = JSONSerializable,
ViewType extends string = string,
> extends WakuObjectMetadata {
onMessage?: (
message: DataMessage<DataMessageType>,
args: WakuObjectArgs<ViewType>,
args: WakuObjectArgs<StoreType, DataMessageType, ViewType>,
) => Promise<void>
}

interface WakuObjectSvelteDescriptor<
StoreType = JSONSerializable,
DataMessageType = JSONSerializable,
ViewType extends string = string,
> extends WakuObjectDescriptor<ViewType> {
> extends WakuObjectDescriptor<StoreType, DataMessageType, ViewType> {
readonly wakuObject: ComponentType
readonly standalone?: ComponentType
}

0 comments on commit 9900ac4

Please sign in to comment.