Skip to content

Instantly share code, notes, and snippets.

@jwulf
Last active February 29, 2020 09:21
Show Gist options
  • Select an option

  • Save jwulf/b348521de01517647502161b65e5b36f to your computer and use it in GitHub Desktop.

Select an option

Save jwulf/b348521de01517647502161b65e5b36f to your computer and use it in GitHub Desktop.
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