-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved heavy calculations into a worker
- Loading branch information
Showing
17 changed files
with
157 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import '../../packages/wasm_exec.js'; | ||
import { JqParams, TokenizeParams } from '@core/background'; | ||
import { jq } from '@packages/jq'; | ||
import { tokenize } from '@packages/tokenizer'; | ||
import { is } from './helpres'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-deprecated | ||
chrome.runtime.onMessage.addListener(function (message: TokenizeParams | JqParams | object, _, sendResponse) { | ||
if (is(message, 'tokenize')) { | ||
tokenize(message.json) | ||
.then(sendResponse) | ||
.catch((err: Error) => | ||
sendResponse({ | ||
type: 'error', | ||
scope: 'worker', | ||
stack: err.stack, | ||
error: err.message, | ||
}) | ||
); | ||
|
||
return true; | ||
} | ||
|
||
if (is(message, 'jq')) { | ||
jq(message.json, message.query) | ||
.then(sendResponse) | ||
.catch((err: Error) => | ||
sendResponse({ | ||
type: 'error', | ||
scope: 'worker', | ||
stack: err.stack, | ||
error: err.message, | ||
}) | ||
); | ||
|
||
return true; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { JqParams, Message, TokenizeParams } from '@core/background'; | ||
|
||
interface Types { | ||
jq: JqParams; | ||
tokenize: TokenizeParams; | ||
} | ||
|
||
export const is = <T extends Message['action']>(message: object, type: T): message is Types[T] => { | ||
return 'action' in message && message.action == type; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './tokenize'; | ||
export * from './models'; | ||
export * from './jq'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { JqParams } from '@core/background/models'; | ||
import { sendMessage } from '@core/browser'; | ||
import { TokenizerResponse } from '@packages/tokenizer'; | ||
|
||
export const jq = async (json: string, query: string): Promise<TokenizerResponse> => { | ||
return sendMessage<JqParams, TokenizerResponse>({ action: 'jq', json, query }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TokenizerResponse } from '@packages/tokenizer'; | ||
|
||
export interface TokenizeParams { | ||
action: 'tokenize'; | ||
json: string; | ||
} | ||
|
||
export interface JqParams { | ||
action: 'jq'; | ||
json: string; | ||
query: string; | ||
} | ||
|
||
export type Message = TokenizeParams | JqParams; | ||
|
||
export { TokenizerResponse }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { TokenizeParams } from '@core/background/models'; | ||
import { sendMessage } from '@core/browser'; | ||
import { TokenizerResponse } from '@packages/tokenizer'; | ||
|
||
export const tokenize = async (json: string): Promise<TokenizerResponse> => { | ||
return sendMessage<TokenizeParams, TokenizerResponse>({ action: 'tokenize', json }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-deprecated | ||
const getURL = chrome.runtime.getURL; | ||
const { getURL, sendMessage } = chrome.runtime; | ||
|
||
export { getURL }; | ||
export { getURL, sendMessage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters