Skip to content

Commit

Permalink
feat: upgrade to async-call@4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Jul 23, 2020
1 parent 0217094 commit d90b13d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@servie/events": "^1.0.0",
"async-call-rpc": "^1.0.4",
"async-call-rpc": "^4.0.0",
"concurrent-lock": "^1.0.7",
"jsx-jsonml-devtools-renderer": "^1.4.1",
"lodash-es": "^4.17.15",
Expand Down
5 changes: 4 additions & 1 deletion src/Extension/AutomatedTabTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ export function AutomatedTabTask<T extends Record<string, (...args: any[]) => Pr
}
const AsyncCallKey = AsyncCallOptions.key
const REGISTER = AsyncCallKey + ':ping'
const finalAsyncCallOptions = { messageChannel: new MessageCenter(false), ...AsyncCallOptions }
const finalAsyncCallOptions: AsyncCallOptions = {
channel: new MessageCenter(false, AsyncCallKey).eventBasedChannel,
...AsyncCallOptions,
}
if (GetContext() === 'content') {
// If run in content script
// Register this tab
Expand Down
12 changes: 8 additions & 4 deletions src/Extension/MessageCenter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Emitter } from '@servie/events'
import { NoSerialization } from 'async-call-rpc'
import { NoSerialization, EventBasedChannel } from 'async-call-rpc'
/**
* Define how to do serialization and deserialization of remote procedure call
*/
Expand All @@ -8,12 +8,12 @@ export interface Serialization {
* Do serialization
* @param from - original data
*/
serialization(from: any): PromiseLike<unknown>
serialization(from: any): unknown | PromiseLike<unknown>
/**
* Do deserialization
* @param serialized - Serialized data
*/
deserialization(serialized: unknown): PromiseLike<any>
deserialization(serialized: unknown): unknown | PromiseLike<unknown>
}
type InternalMessageType = {
key: string
Expand Down Expand Up @@ -102,7 +102,7 @@ export class MessageCenter<ITypedMessages> {
if (typeof browser !== 'undefined') {
browser.runtime?.sendMessage?.(serialized).catch(noop)
// Send message to Content Script
browser.tabs?.query({ discarded: false }).then(tabs => {
browser.tabs?.query({ discarded: false }).then((tabs) => {
for (const tab of tabs) {
if (tab.id !== undefined) browser.tabs.sendMessage(tab.id, serialized).catch(noop)
}
Expand All @@ -120,4 +120,8 @@ export class MessageCenter<ITypedMessages> {
this.log = on
return this
}
eventBasedChannel: EventBasedChannel = {
on: (e) => this.on('__async-call' as any, e),
send: (e) => this.emit('__async-call' as any, e as any),
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,10 @@ astral-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==

async-call-rpc@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/async-call-rpc/-/async-call-rpc-1.0.4.tgz#ded3ef0fac75d0ae90e0ac574adda1ffae4a5cc9"
integrity sha512-dsLSfuF+n1GmgsL5Y+uGCkd+/wYZtHObKPxUncEoJ05bb1Lk3wUlU4ppTXL5sBsRuIXPEUxEdb6w86d0u59udg==
async-call-rpc@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/async-call-rpc/-/async-call-rpc-4.0.0.tgz#825aecfd54bed4873b70ae027ca5a4d0655949e4"
integrity sha512-sDNNa5BIgUYknloEAacx4ool/CKU+IZF8tzbvVGPO8s0ivTcKse7YLsG1U9aBcrXtkdAdqR1nEFNmTdZO6CycA==

asynckit@^0.4.0:
version "0.4.0"
Expand Down

0 comments on commit d90b13d

Please sign in to comment.