Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 3 additions & 41 deletions packages/functorial/src/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* @module
*/

import { assert } from "@std/assert/assert";
import { assertExists } from "@std/assert/exists";

/**
* This type can be assigned to any constructor
*/
Expand Down Expand Up @@ -78,47 +81,6 @@ interface NotificationTarget {
deps?: string[] | undefined;
}

class AssertionError extends Error {
/** Constructs a new instance.
*
* @param message The error message.
* @param options Additional options.
*/
constructor(message: string, options?: ErrorOptions) {
super(message, options);
this.name = "AssertionError";
}
}

/**
* Makes an assertion and throws if `expr` does not have a truthy value.
*
* @param expr The expression to test.
* @param msg The optional message to display if the assertion fails.
*/
function assert(expr: unknown, msg = ""): asserts expr {
if (!expr) throw new AssertionError(msg);
}

/**
* Makes an assertion that `actual` is not null or undefined.
* If not then throws.
*
* @param actual The actual value to check.
* @param msg The optional message to include in the error if the assertion fails.
*/
function assertExists<T>(
actual: T,
msg?: string,
): asserts actual is NonNullable<T> {
if (actual === undefined || actual === null) {
const msgSuffix = msg ? `: ${msg}` : ".";
msg =
`Expected actual: "${actual}" to not be null or undefined${msgSuffix}`;
throw new AssertionError(msg);
}
}

class Scheduler {
#callback: () => void;
#pending: Map<Record<PropertyKey, any>, ReactiveEvent[]> = new Map();
Expand Down