fix typos in typescript definition, reword some vars

This commit is contained in:
B. Petersen 2022-01-28 16:59:33 +01:00 committed by bjoern
parent aadea2951a
commit aca5489122
3 changed files with 15 additions and 14 deletions

View file

@ -30,7 +30,7 @@ just add these two lines to your javascript source files:
```js
//@ts-check
/** @typedef {import('./webxdc').WEBxDC} WEBxDC */
/** @typedef {import('./webxdc').Webxdc} WEBxDC */
```
Without vscode you need to install typescript and then run the check manually.

25
webxdc.d.ts vendored
View file

@ -1,6 +1,6 @@
//@ts-check
type SendingStateUpdate<T> = {
type SendingStatusUpdate<T> = {
/** the payload, deserialized json:
* any javascript primitive, array or object. */
payload: T;
@ -15,12 +15,12 @@ type SendingStateUpdate<T> = {
summary?: string;
};
type RecievedStateUpdate<T> = {
type ReceivedStatusUpdate<T> = {
/** the payload, deserialized json */
payload: T;
};
interface WEBxDC<T> {
interface Webxdc<T> {
/** Returns the peer's own address.
* This is esp. useful if you want to differ between different peers - just send the address along with the payload,
* and, if needed, compare the payload addresses against selfAddr() later on. */
@ -28,31 +28,32 @@ interface WEBxDC<T> {
/** Returns the peer's own name. This is name chosen by the user in their settings, if there is nothing set, that defaults to the peer's address. */
selfName: string;
/**
* set a listener for new state updates
* note that own state updates, that you send with {@link sendStateUpdate}, also trigger this method
* set a listener for new status updates
* note that own status updates, that you send with {@link sendUpdate}, also trigger this method
* */
setUpdateListener(cb: (stateUpdate: RecievedStateUpdate<T>) => void): void;
setUpdateListener(cb: (statusUpdate: ReceivedStatusUpdate<T>) => void): void;
/**
* In case your Webxdc was just started,
* you may want to reconstruct the state from the last run - and also incorporate updates that may have arrived while the app was not running.
* you may want to reconstruct the status from the last run - and also incorporate updates that may have arrived while the app was not running.
*/
getAllUpdates(): Promise<RecievedStateUpdate<T>[]>;
getAllUpdates(): Promise<ReceivedStatusUpdate<T>[]>;
/**
* Webxdc apps are usually shared in a chat and run independently on each peer. To get a shared state, the peers use sendUpdate() to send updates to each other.
* Webxdc apps are usually shared in a chat and run independently on each peer. To get a shared status, the peers use sendUpdate() to send updates to each other.
* @param update status update to send
* @param description short, human-readable description what this update is about. this is shown eg. as a fallback text in an email program.
*/
sendUpdate(update: SendingStateUpdate<T>, description: string): void;
sendUpdate(update: SendingStatusUpdate<T>, description: string): void;
}
////////// ANCHOR: global
declare global {
interface Window {
webxdc: WEBxDC<any>;
webxdc: Webxdc<any>;
}
}
////////// ANCHOR_END: global
export { SendingStateUpdate, RecievedStateUpdate, WEBxDC };
export { SendingStatusUpdate, ReceivedStatusUpdate, Webxdc };
/* Types for the Simulator */
declare global {

View file

@ -1,6 +1,6 @@
// debug friend: document.writeln(JSON.stringify(value));
//@ts-check
/** @type {import('./webxdc').WEBxDC<any>} */
/** @type {import('./webxdc').Webxdc<any>} */
window.webxdc = (() => {
var updateListener = (_) => {};
var updatesKey = "__xdcUpdatesKey__";