forked from Power-Playground/app
-
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.
feat(core): abstract messenger to support message display function
- Loading branch information
Showing
5 changed files
with
62 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export interface Messenger { | ||
display( | ||
type: | ||
| 'success' | ||
| 'info' | ||
| 'warning' | ||
| 'error', | ||
message: React.ReactNode, | ||
options?: { | ||
duration?: number | ||
closable?: boolean | ||
position?: | ||
| 'top-center' | ||
| 'top-right' | ||
| 'bottom-center' | ||
| 'bottom-right' | ||
} | ||
): void | ||
} | ||
|
||
let instance: Messenger | null = null | ||
|
||
let messengerPromiseResolve: (messenger: Messenger) => void | ||
|
||
export const messenger: Promise<Messenger> = new Promise((resolve) => { | ||
if (instance) { | ||
resolve(instance) | ||
} else { | ||
messengerPromiseResolve = resolve | ||
} | ||
}) | ||
|
||
export function provideMessenger(messenger: Messenger) { | ||
instance = messenger | ||
messengerPromiseResolve(messenger) | ||
} |
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