Skip to content

Commit

Permalink
Improve message typing
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanw committed Dec 26, 2023
1 parent f222f4f commit 4901235
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Reader {
this.cleanUp()
}

postMessage (message) {
postMessage (message: Message) {
try {
this.port.postMessage(message)
} catch (e) {
Expand All @@ -92,7 +92,7 @@ class Reader {
this.sourceBot.run()
}

botCallback (event) {
botCallback (event: Message) {
if (event.type === STATUS_MESSAGE) {
this.sendStatusMessage(event)
} else if (event.type === FAILED_MESSAGE) {
Expand All @@ -115,15 +115,15 @@ class Reader {
}
this.postMessage({
type: SUCCESS_MESSAGE,
content: event.message,
content: event.content,
saveArticle: storageItems.saveArticle
})
}

fail (event) {
this.postMessage({
type: FAILED_MESSAGE,
content: event.message
message: event.message
})
this.cleanUp()
}
Expand Down
2 changes: 1 addition & 1 deletion src/sitebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class SiteBot implements SiteBotInterface {
this.port.onDisconnect.removeListener(this.onDisconnect)
}

onMessage (event) {
onMessage (event: Message) {
console.log(LOG_NAME, event)
if (event.type === ABORT_MESSAGE) {
this.showPaywall()
Expand Down
4 changes: 2 additions & 2 deletions src/sourcebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ class SourceBot {
}
}

finalize (result) {
finalize (result: string) {
this.done = true
if (result.length > 0) {
this.callback({
type: SUCCESS_MESSAGE,
message: result
content: result
})

browser.tabs.remove(this.tabId)
Expand Down
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,21 @@ export type GoToTabMessage = {
export type StatusMessage = {
type: 'status'
message: string
action?: 'interaction_required'
}

export type SuccessMessage = {
type: 'success'
message: string
content: string
saveArticle?: string | null
}

export type FailedMessage = {
type: 'failed'
message: string
}

export type Message = InitMessage | GoToTabMessage | StatusMessage | SuccessMessage | FailedMessage
export type Message = InitMessage | GoToTabMessage | StatusMessage | SuccessMessage | FailedMessage | AbortMessage

export type FillAction = {
fill: {
Expand Down

0 comments on commit 4901235

Please sign in to comment.