@tur-ng/std 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -1
- package/src/index.d.ts +50 -34
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tur-ng/std",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "src/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -14,5 +14,8 @@
|
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/hpp2334/tur.git",
|
|
16
16
|
"directory": "js/packages/tur-std"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@tur-ng/core": "0.0.7"
|
|
17
20
|
}
|
|
18
21
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -18,13 +18,17 @@
|
|
|
18
18
|
* substrate may import directly from `tur:core`.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
+
/// <reference types="@tur-ng/core" />
|
|
22
|
+
|
|
21
23
|
declare module "tur:std" {
|
|
22
24
|
// Re-export the reactive core (source/derive/mutate/get/set/view/mount,
|
|
23
25
|
// Element/Source/Derived/Mutation/Readable/Val, ReadonlyStoreCtx/StoreCtx).
|
|
24
26
|
export * from "tur:core";
|
|
25
27
|
|
|
26
|
-
// Core meta-types used by the prop interfaces below.
|
|
27
|
-
|
|
28
|
+
// Core meta-types used by the prop interfaces below. (`export *` alone
|
|
29
|
+
// re-exports but does not bind names locally — every core type used in
|
|
30
|
+
// this module body must also appear here.)
|
|
31
|
+
import type { Derived, Element, Mutation, Readable, Val } from "tur:core";
|
|
28
32
|
|
|
29
33
|
// ---------------------------------------------------------------------------
|
|
30
34
|
// Value types — Color / LinearGradient / Brush / SpanData
|
|
@@ -584,43 +588,55 @@ declare module "tur:std" {
|
|
|
584
588
|
}
|
|
585
589
|
|
|
586
590
|
// ---------------------------------------------------------------------------
|
|
587
|
-
// Async task primitives — `
|
|
588
|
-
//
|
|
589
|
-
// `
|
|
591
|
+
// Async task primitives — the `Task<T>` handle, `sleep`, `CancelError`,
|
|
592
|
+
// and `isCancelError`. These replace the old `setTimeout` /
|
|
593
|
+
// `setInterval` globals (and the former `launch` generator driver):
|
|
594
|
+
// async composition is plain `async`/`await` + `.then`, cancellation is
|
|
595
|
+
// per-operation via the Task handle.
|
|
590
596
|
// ---------------------------------------------------------------------------
|
|
591
597
|
|
|
592
|
-
/**
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
|
|
598
|
+
/** The handle every async engine API returns: `sleep`, `request`,
|
|
599
|
+
* `requestStream`, `clipboard.readText`/`writeText`,
|
|
600
|
+
* `filePicker.pick`/`saveFile`, …
|
|
601
|
+
*
|
|
602
|
+
* - `promise` settles with the operation's result.
|
|
603
|
+
* - `cancel()` stops the operation where stoppable (a pending `sleep`
|
|
604
|
+
* timer is really cleared; an unpolled HTTP request is never sent;
|
|
605
|
+
* an in-flight one is discarded; a stream is wire-aborted) and
|
|
606
|
+
* **rejects `promise` with a `CancelError`**. Idempotent; a no-op
|
|
607
|
+
* for the promise once settled (op-specific abort still runs — e.g.
|
|
608
|
+
* cancelling a stream mid-consumption).
|
|
609
|
+
*
|
|
610
|
+
* Debounce idiom (the no-op rejection handler IS the cancelled
|
|
611
|
+
* branch):
|
|
612
|
+
* ```ts
|
|
613
|
+
* t?.cancel(); t = sleep(300);
|
|
614
|
+
* t.promise.then(show, () => {});
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* Loop stop idiom: cancel the awaited sleep; the `await` throws
|
|
618
|
+
* `CancelError`; `catch (e) { if (isCancelError(e)) return; throw e; }`
|
|
619
|
+
* exits the loop. */
|
|
620
|
+
export interface Task<T> {
|
|
621
|
+
readonly promise: Promise<T>;
|
|
601
622
|
cancel(): void;
|
|
602
623
|
}
|
|
603
624
|
|
|
604
|
-
/**
|
|
605
|
-
*
|
|
606
|
-
*
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
* `
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
|
|
619
|
-
* pattern: `task?.cancel(); task = launch(function* () { yield sleep(ms);
|
|
620
|
-
* ... });`. */
|
|
621
|
-
export function launch<T>(
|
|
622
|
-
gen: () => Generator<Promise<unknown>, T, unknown>,
|
|
623
|
-
): Task;
|
|
625
|
+
/** The rejection reason produced by `Task.cancel()` — an `Error` whose
|
|
626
|
+
* `name` is `"CancelError"`. Test with `isCancelError` (or
|
|
627
|
+
* `e.name === "CancelError"`). */
|
|
628
|
+
export interface CancelError extends Error {
|
|
629
|
+
name: "CancelError";
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/** `true` when `reason` is the rejection produced by `Task.cancel()`. */
|
|
633
|
+
export function isCancelError(reason: unknown): reason is CancelError;
|
|
634
|
+
|
|
635
|
+
/** Sleep for `ms` milliseconds (engine time) — the engine's frame loop
|
|
636
|
+
* wakes precisely at the deadline. Returns a `Task<void>`: await
|
|
637
|
+
* `sleep(ms).promise`, and `cancel()` to clear the timer (the promise
|
|
638
|
+
* then rejects with a `CancelError`). */
|
|
639
|
+
export function sleep(ms: number): Task<void>;
|
|
624
640
|
|
|
625
641
|
// ---------------------------------------------------------------------------
|
|
626
642
|
// Element factories
|