-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: implement
onAbort()
and soft-deprecate `onTelefunctionRemoteCa…
…llError()`
- Loading branch information
Showing
8 changed files
with
62 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
export type { TelefunctionError } | ||
export type { TelefunctionCallAbort } | ||
|
||
type TelefunctionError = Error & | ||
( | ||
| { | ||
isConnectionError?: undefined | ||
isAbort?: undefined | ||
} | ||
| { | ||
isConnectionError: true | ||
isAbort?: undefined | ||
} | ||
| { | ||
isConnectionError?: undefined | ||
isAbort: true | ||
abortValue: unknown | ||
} | ||
) | ||
type TelefunctionError = TelefunctionCallErrorSsr | TelefunctionCallErrorConnection | TelefunctionCallAbort | ||
|
||
type TelefunctionCallErrorSsr = Error & { | ||
isConnectionError?: undefined | ||
isAbort?: undefined | ||
} | ||
type TelefunctionCallErrorConnection = Error & { | ||
isConnectionError: true | ||
isAbort?: undefined | ||
} | ||
type TelefunctionCallAbort = Error & { | ||
isConnectionError?: undefined | ||
isAbort: true | ||
abortValue: unknown | ||
} |
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,5 +1,5 @@ | ||
export { telefuncConfig } from './clientConfig' | ||
export { onTelefunctionRemoteCallError } from './remoteTelefunctionCall/onTelefunctionRemoteCallError' | ||
export { onAbort, onTelefunctionRemoteCallError } from './remoteTelefunctionCall/onAbort' | ||
export type { TelefunctionError } from './TelefunctionError' | ||
|
||
export { remoteTelefunctionCall as __remoteTelefunctionCall } from './remoteTelefunctionCall' |
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,34 @@ | ||
export { onAbort } | ||
export { callOnAbortListeners } | ||
export { onTelefunctionRemoteCallError } | ||
|
||
import type { TelefunctionError, TelefunctionCallAbort } from '../TelefunctionError' | ||
import { assertWarning } from '../utils' | ||
|
||
type Listener = (err: TelefunctionCallAbort) => void | ||
|
||
/** Outdated: use onAbort() instead */ | ||
function onTelefunctionRemoteCallError(listener: (err: TelefunctionError) => void) { | ||
assertWarning(false, 'onTelefunctionRemoteCallError() deprecated in favor of onAbort()', { | ||
onlyOnce: true, | ||
showStackTrace: true | ||
}) | ||
onAbort(listener) | ||
} | ||
|
||
function onAbort(listener: Listener) { | ||
window.__telefunc_errorListeners = window.__telefunc_errorListeners || [] | ||
window.__telefunc_errorListeners.push(listener) | ||
} | ||
|
||
function callOnAbortListeners(err: TelefunctionCallAbort) { | ||
;(window.__telefunc_errorListeners || []).forEach((listener) => { | ||
listener(err) | ||
}) | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
__telefunc_errorListeners: Listener[] | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
telefunc/client/remoteTelefunctionCall/onTelefunctionRemoteCallError.ts
This file was deleted.
Oops, something went wrong.
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,3 +1,5 @@ | ||
// no-op | ||
export const telefuncConfig = {} | ||
export const onTelefunctionRemoteCallError = () => {}; | ||
export const onAbort = () => {} | ||
/** @deprecated */ | ||
export const onTelefunctionRemoteCallError = () => {} |