-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
30 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
import type { IState } from './popup/store/types'; | ||
|
||
export const CUSTOM_EVENT_REQUEST = '>_request::velo-filesystem'; | ||
export const CUSTOM_EVENT_RESPONSE = '<_response::velo-filesystem'; | ||
export const enum CUSTOM_EVENT { | ||
REQUEST = '>_request::velo-filesystem', | ||
RESPONSE = '<_response::velo-filesystem', | ||
} | ||
|
||
export const enum RequestEvents { | ||
onmout = '>_onmout', | ||
download = '>_download', | ||
export const enum REQUEST { | ||
READY = '>_ready', | ||
DOWNLOAD = '>_download', | ||
} | ||
|
||
export const enum ResponseEvents { | ||
content_loaded = '<_content_loaded', | ||
export const enum RESPONSE { | ||
LOADED = '<_loaded', | ||
} | ||
|
||
export interface IRequest { | ||
readonly type: RequestEvents; | ||
readonly type: REQUEST; | ||
readonly state: IState; | ||
} | ||
|
||
export interface IResponse { | ||
readonly type: ResponseEvents; | ||
readonly type: RESPONSE; | ||
} | ||
|
||
type TDispatcer<T> = (detail: T) => boolean; | ||
type TListener<T> = (callback: (detail: T) => void) => void | ||
|
||
export const dispatchResponce: TDispatcer<IResponse> = (detail) => | ||
dispatchEvent( | ||
new CustomEvent<IResponse>(CUSTOM_EVENT_RESPONSE, { detail }), | ||
new CustomEvent<IResponse>(CUSTOM_EVENT.RESPONSE, { detail }), | ||
); | ||
|
||
export const dispatchRequest: TDispatcer<IRequest> = (detail) => | ||
dispatchEvent( | ||
new CustomEvent<IRequest>(CUSTOM_EVENT_REQUEST, { detail }), | ||
new CustomEvent<IRequest>(CUSTOM_EVENT.REQUEST, { detail }), | ||
); | ||
|
||
export const addResponseListener: TListener<IResponse> = (callback) => | ||
addEventListener(CUSTOM_EVENT_RESPONSE, (event) => callback(event.detail)); | ||
addEventListener(CUSTOM_EVENT.RESPONSE, (event) => callback(event.detail)); | ||
|
||
|
||
export const addRequestListener: TListener<IRequest> = (callback) => | ||
addEventListener(CUSTOM_EVENT_REQUEST, (event) => callback(event.detail)); | ||
addEventListener(CUSTOM_EVENT.REQUEST, (event) => callback(event.detail)); |
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