Last active
February 29, 2020 09:21
-
-
Save jwulf/b348521de01517647502161b65e5b36f to your computer and use it in GitHub Desktop.
A code sample from the article https://www.joshwulf.com/blog/2020/02/refining-method-signature/
This file contains hidden or 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
| export function decodeCreateZBWorkerSig(config) { | |
| const isShorthandSig = typeof config.taskTypeOrTaskHandler === 'function' | |
| const taskHandler: ZB.ZBWorkerTaskHandler = isShorthandSig | |
| ? (config.taskTypeOrTaskHandler as ZB.ZBWorkerTaskHandler) | |
| : (config.taskHandlerOrOptions as ZB.ZBWorkerTaskHandler) | |
| const id: string | null = isShorthandSig | |
| ? (config.idOrTaskType as string) | |
| : null | |
| const taskType: string = isShorthandSig | |
| ? (config.idOrTaskType as string) | |
| : (config.taskTypeOrTaskHandler as string) | |
| const options: ZB.ZBWorkerOptions & ZB.ZBClientOptions = | |
| (isShorthandSig | |
| ? config.taskHandlerOrOptions | |
| : config.optionsOrOnConnectionError) || {} | |
| const onConnectionError = isShorthandSig | |
| ? config.optionsOrOnConnectionError | |
| : config.onConnectionError || | |
| options.onConnectionError || | |
| config.onConnectionError | |
| const onReady = options.onReady | |
| return { | |
| id, | |
| onConnectionError, | |
| onReady, | |
| options, | |
| taskHandler, | |
| taskType, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment