Skip to content

Commit

Permalink
feat: update AppConfigAPI types (#753)
Browse files Browse the repository at this point in the history
* feat: update AppConfigAPI types

* feat: improve callback and return types

* fix: use KeyValueMap
  • Loading branch information
andipaetzold authored May 31, 2021
1 parent 536508c commit 6876d0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 10 additions & 4 deletions lib/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Channel } from './channel'
import { AppConfigAPI, AppState } from './types'
import { KeyValueMap } from './types/entities'

const HOOK_STAGE_PRE_INSTALL = 'preInstall'
const HOOK_STAGE_POST_INSTALL = 'postInstall'
Expand Down Expand Up @@ -97,16 +98,21 @@ export default function createApp(channel: Channel): AppConfigAPI {
isInstalled() {
return channel.call('callAppMethod', 'isInstalled') as Promise<boolean>
},
getParameters() {
return channel.call('callAppMethod', 'getParameters') as Promise<any>
getParameters<T extends KeyValueMap = KeyValueMap>() {
return channel.call('callAppMethod', 'getParameters') as Promise<T | null>
},
getCurrentState() {
return channel.call('callAppMethod', 'getCurrentState') as Promise<AppState | null>
},
onConfigure(handler: Function) {
onConfigure(
handler: () => {
parameters?: KeyValueMap
targetState?: AppState
}
) {
setHandler(HOOK_STAGE_PRE_INSTALL, handler)
},
onConfigurationCompleted(handler: Function) {
onConfigurationCompleted(handler: (err: null | { message: string }) => void) {
setHandler(HOOK_STAGE_POST_INSTALL, handler)
},
}
Expand Down
13 changes: 9 additions & 4 deletions lib/types/app.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentType } from './entities'
import { ContentType, KeyValueMap } from './entities'

interface AppStateEditorInterfaceItem {
controls?: Array<{ fieldId: string; settings?: Record<string, any> }>
Expand All @@ -22,9 +22,14 @@ export interface AppConfigAPI {
/** Returns current state of an App */
getCurrentState: () => Promise<AppState | null>
/** Returns parameters of an App, null otherwise */
getParameters: <T = Object>() => Promise<null | T>
getParameters: <T extends KeyValueMap = KeyValueMap>() => Promise<null | T>
/** Registers a handler to be called to produce parameters for an App */
onConfigure: (handler: Function) => void
onConfigure: (
handler: () => {
parameters?: KeyValueMap
targetState?: AppState
}
) => void
/** Registers a handler to be called once configuration was finished */
onConfigurationCompleted: (handler: Function) => void
onConfigurationCompleted: (handler: (err: null | { message: string }) => void) => void
}

0 comments on commit 6876d0a

Please sign in to comment.