@thi.ng/rdom 0.14.0 → 1.0.0

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-28T23:24:39Z
3
+ - **Last updated**: 2024-01-23T15:58:26Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,21 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ # [1.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@1.0.0) (2024-01-23)
13
+
14
+ #### 🛑 Breaking changes
15
+
16
+ - remove scheduler, update IComponent signatures ([3728c9b](https://github.com/thi-ng/umbrella/commit/3728c9b))
17
+ - BREAKING CHANGE: remove scheduler, update IComponent and
18
+ various DOM update fn signatures
19
+ - remove scheduler support since never used (other than
20
+ default/dummy `NullScheduler`) and `RAFScheduler` logic is
21
+ better handled via `synRAF()` or similar (also see [#402](https://github.com/thi-ng/umbrella/issues/402))
22
+ - update IComponent.mount() signature to use `ParentNode
23
+ as type for `parent` arg, e.g. to support use w/ `ShadowRoot`
24
+ - update various DOM update fns with same parent arg type
25
+ - update all utility components/wrappers
26
+
12
27
  ## [0.14.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/rdom@0.14.0) (2023-12-28)
13
28
 
14
29
  #### 🚀 Features
package/README.md CHANGED
@@ -7,13 +7,14 @@
7
7
  ![npm downloads](https://img.shields.io/npm/dm/@thi.ng/rdom.svg)
8
8
  [![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)](https://mastodon.thi.ng/@toxi)
9
9
 
10
- This project is part of the
11
- [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo and anti-framework.
10
+ This is a standalone project, maintained as part of the
11
+ [@thi.ng/umbrella](https://github.com/thi-ng/umbrella/) monorepo and
12
+ anti-framework.
12
13
 
13
14
  - [About](#about)
14
15
  - [From hdom to rdom: Reactive UIs without virtual DOMs](#from-hdom-to-rdom-reactive-uis-without-virtual-doms)
15
16
  - [Targetted, isolated updates](#targetted-isolated-updates)
16
- - [Async updates, scheduling & life cycle methods](#async-updates-scheduling--life-cycle-methods)
17
+ - [Async updates & life cycle methods](#async-updates--life-cycle-methods)
17
18
  - [@thi.ng/atom integration](#thingatom-integration)
18
19
  - [DOM creation & mutation](#dom-creation--mutation)
19
20
  - [Control structures](#control-structures)
@@ -89,18 +90,12 @@ wrapper provides a component which subscribes to a stream of hiccup-based scene
89
90
  descriptions (trees) and then translates each scene-value into HTML Canvas API
90
91
  draw calls.
91
92
 
92
- ### Async updates, scheduling & life cycle methods
93
+ ### Async updates & life cycle methods
93
94
 
94
95
  Since there's no central coordination in _rdom_ (neither explicitly nor
95
96
  implicitly), each component can (and does) update whenever its state value has
96
97
  changed. Likewise, components are free to directly manipulate the DOM through
97
- other means, as hinted at earlier. Various _rdom_ control constructs are
98
- dispatching component updates via a central scheduler. By default this is only a
99
- dummy implementation which processes tasks immediately. However, as usual _rdom_
100
- only relies on the
101
- [`IScheduler`](https://docs.thi.ng/umbrella/rdom/interfaces/IScheduler.html)
102
- interface and so supports other implementations, like
103
- [`RAFScheduler`](https://docs.thi.ng/umbrella/rdom/classes/RAFScheduler.html).
98
+ other means, as hinted at earlier.
104
99
 
105
100
  The [`IComponent`](https://docs.thi.ng/umbrella/rdom/interfaces/icomponent.html)
106
101
  interface is at the heart of _rdom_. It defines three lifecycle methods to:
@@ -281,7 +276,7 @@ For Node.js REPL:
281
276
  const rdom = await import("@thi.ng/rdom");
282
277
  ```
283
278
 
284
- Package sizes (brotli'd, pre-treeshake): ESM: 4.19 KB
279
+ Package sizes (brotli'd, pre-treeshake): ESM: 3.99 KB
285
280
 
286
281
  ## Dependencies
287
282
 
@@ -450,4 +445,4 @@ If this project contributes to an academic publication, please cite it as:
450
445
 
451
446
  ## License
452
447
 
453
- © 2020 - 2023 Karsten Schmidt // Apache License 2.0
448
+ © 2020 - 2024 Karsten Schmidt // Apache License 2.0
package/api.d.ts CHANGED
@@ -21,7 +21,7 @@ export interface IComponent<T = any> {
21
21
  * mount the component in the parent element and SHOULD default to
22
22
  * -1, causing the component to be appended to (rather than inserted
23
23
  * into) the list of children. The `index` arg MUST be passed to any
24
- * DOM creation functions used within `mount()` (e.g. {@link el},
24
+ * DOM creation functions used within `mount()` (e.g. {@link $el},
25
25
  * {@link $tree}). Likewise, for control-flow or wrapper components,
26
26
  * the `index` arg MUST be used when mounting child components
27
27
  * in-place of the wrapper component itself (e.g. see {@link $list},
@@ -34,7 +34,7 @@ export interface IComponent<T = any> {
34
34
  * @param idx -
35
35
  * @param xs -
36
36
  */
37
- mount(parent: Element, idx?: NumOrElement, ...xs: any[]): Promise<Element>;
37
+ mount(parent: ParentNode, idx?: NumOrElement, ...xs: any[]): Promise<Element>;
38
38
  /**
39
39
  * Async component lifecycle method to remove the component from the
40
40
  * target DOM and release any other internal resources (e.g.
@@ -65,7 +65,7 @@ export interface IMountWith<T, M> extends IComponent<T> {
65
65
  * @param index -
66
66
  * @param state -
67
67
  */
68
- mount(parent: Element, index: NumOrElement, state: M): Promise<Element>;
68
+ mount(parent: ParentNode, index: NumOrElement, state: M): Promise<Element>;
69
69
  /**
70
70
  * Same like {@link IComponent.update}, but new `state` value arg is
71
71
  * mandatory.
@@ -90,27 +90,5 @@ export interface CompiledComponent extends IComponent {
90
90
  */
91
91
  export type ComponentLike = IComponent | [string, ...(any | null)[]];
92
92
  export type Callback = Fn0<void>;
93
- export type Task = Fn0<void>;
94
93
  export type NumOrElement = number | Element;
95
- /**
96
- * Interface for task schedulers. See {@link NullScheduler} and
97
- * {@link RAFScheduler}.
98
- */
99
- export interface IScheduler {
100
- /**
101
- * Registers a new task for processing. The `scope` arg is used to uniquely
102
- * associate the task with a given component.
103
- *
104
- * @param scope -
105
- * @param task -
106
- */
107
- add(scope: any, task: Task): void;
108
- /**
109
- * Attempts to cancel all tasks for given `scope`. Depending on
110
- * implementation and timing this might not be possible (anymore).
111
- *
112
- * @param scope -
113
- */
114
- cancel(scope: any): void;
115
- }
116
94
  //# sourceMappingURL=api.d.ts.map
package/compile.js CHANGED
@@ -3,7 +3,6 @@ import { isPlainObject } from "@thi.ng/checks/is-plain-object";
3
3
  import { isSubscribable } from "@thi.ng/rstream/checks";
4
4
  import { isComponent, isElement } from "./checks.js";
5
5
  import { $el, $remove, $tree } from "./dom.js";
6
- import { SCHEDULER } from "./scheduler.js";
7
6
  import { $SubA, $sub } from "./sub.js";
8
7
  import { $wrapEl, $wrapText } from "./wrap.js";
9
8
  const $compile = (tree) => isArray(tree) ? isComplexComponent(tree) ? complexComponent(tree) : basicComponent(tree) : isComponent(tree) ? tree : isSubscribable(tree) ? $sub(tree, "span") : tree instanceof Element ? $wrapEl(tree) : $wrapText("span", null, tree);
@@ -45,17 +44,14 @@ const complexComponent = (tree) => ({
45
44
  return this.el;
46
45
  },
47
46
  async unmount() {
48
- SCHEDULER.cancel(this);
49
47
  if (this.children) {
50
48
  for (let c of this.children) {
51
49
  await c.unmount();
52
50
  }
53
51
  }
54
52
  this.subs && this.subs.forEach((s) => s.unsubscribe());
55
- $remove(this.el);
56
- this.children = void 0;
57
- this.subs = void 0;
58
- this.el = void 0;
53
+ this.el && $remove(this.el);
54
+ this.el = this.children = this.subs = void 0;
59
55
  },
60
56
  update() {
61
57
  }
@@ -65,7 +61,7 @@ const basicComponent = (tree) => ({
65
61
  return this.el = await $tree(tree, parent, index);
66
62
  },
67
63
  async unmount() {
68
- $remove(this.el);
64
+ this.el && $remove(this.el);
69
65
  this.el = void 0;
70
66
  },
71
67
  update() {
package/component.d.ts CHANGED
@@ -7,7 +7,7 @@ import type { IComponent, NumOrElement } from "./api.js";
7
7
  */
8
8
  export declare abstract class Component<T = any> implements IComponent<T> {
9
9
  el?: Element;
10
- abstract mount(parent: Element, index?: NumOrElement, ...xs: any[]): Promise<Element>;
10
+ abstract mount(parent: ParentNode, index?: NumOrElement, ...xs: any[]): Promise<Element>;
11
11
  unmount(): Promise<void>;
12
12
  update(state?: T): void;
13
13
  /**
@@ -20,7 +20,7 @@ export declare abstract class Component<T = any> implements IComponent<T> {
20
20
  * @param parent
21
21
  * @param idx
22
22
  */
23
- $el(tag: string, attribs?: any, body?: any, parent?: Element | undefined, idx?: NumOrElement): Element;
23
+ $el(tag: string, attribs?: any, body?: any, parent?: ParentNode | undefined, idx?: NumOrElement): Element;
24
24
  /**
25
25
  * Syntax sugar for {@link $comment}, creates a new comment DOM node using
26
26
  * this component's {@link IComponent.el} as default `parent`.
@@ -29,7 +29,7 @@ export declare abstract class Component<T = any> implements IComponent<T> {
29
29
  * @param parent
30
30
  * @param idx
31
31
  */
32
- $comment(body: string | string[], parent?: Element | undefined, idx?: NumOrElement): Comment;
32
+ $comment(body: string | string[], parent?: ParentNode | undefined, idx?: NumOrElement): Comment;
33
33
  /**
34
34
  * Syntax sugar for {@link $clear}, using this component's
35
35
  * {@link IComponent.el} as default element to clear.
@@ -50,7 +50,7 @@ export declare abstract class Component<T = any> implements IComponent<T> {
50
50
  * @param root
51
51
  * @param index
52
52
  */
53
- $tree(tree: any, root?: Element, index?: NumOrElement): Promise<any>;
53
+ $tree(tree: any, root?: ParentNode, index?: NumOrElement): Promise<any>;
54
54
  /**
55
55
  * Syntax sugar for {@link $text}, using this component's
56
56
  * {@link IComponent.el} as default element to edit.
@@ -62,7 +62,7 @@ export declare abstract class Component<T = any> implements IComponent<T> {
62
62
  * @param body
63
63
  * @param el
64
64
  */
65
- $text(body: any, el?: HTMLElement): void;
65
+ $text(body: any, el?: HTMLElement | SVGElement): void;
66
66
  /**
67
67
  * Syntax sugar for {@link $html}, using this component's
68
68
  * {@link IComponent.el} as default element to edit.
@@ -106,6 +106,6 @@ export declare abstract class Component<T = any> implements IComponent<T> {
106
106
  * @param el
107
107
  * @param idx
108
108
  */
109
- $moveTo(newParent: Element, el?: Element, idx?: NumOrElement): void;
109
+ $moveTo(newParent: ParentNode, el?: Element, idx?: NumOrElement): void;
110
110
  }
111
111
  //# sourceMappingURL=component.d.ts.map
package/dom.d.ts CHANGED
@@ -26,7 +26,7 @@ import type { NumOrElement } from "./api.js";
26
26
  * @param parent -
27
27
  * @param idx -
28
28
  */
29
- export declare const $tree: (tree: any, parent: Element, idx?: NumOrElement) => Promise<any>;
29
+ export declare const $tree: (tree: any, parent: ParentNode, idx?: NumOrElement) => Promise<any>;
30
30
  /**
31
31
  * Create a single DOM element and optionally attaches it to `parent`.
32
32
  *
@@ -49,7 +49,7 @@ export declare const $tree: (tree: any, parent: Element, idx?: NumOrElement) =>
49
49
  * @param parent -
50
50
  * @param idx -
51
51
  */
52
- export declare const $el: (tag: string, attribs: any, body?: any, parent?: Element, idx?: NumOrElement) => Element;
52
+ export declare const $el: (tag: string, attribs: any, body?: any, parent?: ParentNode, idx?: NumOrElement) => Element;
53
53
  /**
54
54
  * Similar to {@link $el}, but creates a new comment DOM node using provided
55
55
  * body. If `parent` is given, the comment will be attached or inserted as child
@@ -63,7 +63,7 @@ export declare const $el: (tag: string, attribs: any, body?: any, parent?: Eleme
63
63
  * @param parent
64
64
  * @param idx
65
65
  */
66
- export declare const $comment: (body: string | string[], parent?: Element, idx?: NumOrElement) => Comment;
66
+ export declare const $comment: (body: string | string[], parent?: ParentNode, idx?: NumOrElement) => Comment;
67
67
  /**
68
68
  * Appends or inserts `child` as child element of `parent`. The default `idx` of
69
69
  * -1 means the child will be appended, else uses `parent.insertBefore()` to
@@ -73,7 +73,7 @@ export declare const $comment: (body: string | string[], parent?: Element, idx?:
73
73
  * @param child
74
74
  * @param idx
75
75
  */
76
- export declare const $addChild: (parent: Element, child: Element | Comment, idx?: NumOrElement) => void;
76
+ export declare const $addChild: (parent: ParentNode, child: Node | Comment, idx?: NumOrElement) => void;
77
77
  /**
78
78
  * Removes given element or comment from the DOM.
79
79
  *
@@ -88,7 +88,7 @@ export declare const $remove: (el: Element | Comment) => void;
88
88
  * @param el
89
89
  * @param idx
90
90
  */
91
- export declare const $moveTo: (newParent: Element, el: Element | Comment, idx?: NumOrElement) => void;
91
+ export declare const $moveTo: (newParent: ParentNode, el: Element | Comment, idx?: NumOrElement) => void;
92
92
  /**
93
93
  * Removes all content from given element.
94
94
  *
package/index.d.ts CHANGED
@@ -11,7 +11,6 @@ export * from "./list.js";
11
11
  export * from "./object.js";
12
12
  export * from "./promise.js";
13
13
  export * from "./replace.js";
14
- export * from "./scheduler.js";
15
14
  export * from "./sub.js";
16
15
  export * from "./switch.js";
17
16
  export * from "./wrap.js";
package/index.js CHANGED
@@ -11,7 +11,6 @@ export * from "./list.js";
11
11
  export * from "./object.js";
12
12
  export * from "./promise.js";
13
13
  export * from "./replace.js";
14
- export * from "./scheduler.js";
15
14
  export * from "./sub.js";
16
15
  export * from "./switch.js";
17
16
  export * from "./wrap.js";
package/klist.d.ts CHANGED
@@ -67,7 +67,7 @@ export declare class KList<T> extends Component<T[]> implements IMountWithState<
67
67
  items?: KListItem[];
68
68
  cache?: Map<NumOrString, KListItem>;
69
69
  constructor(tag: string, attribs: any, ctor: Fn<T, any>, keyFn?: Fn2<T, number, NumOrString>);
70
- mount(parent: Element, index: NumOrElement, state: T[]): Promise<Element>;
70
+ mount(parent: ParentNode, index: NumOrElement, state: T[]): Promise<Element>;
71
71
  unmount(): Promise<void>;
72
72
  update(curr: T[]): Promise<void>;
73
73
  }
package/klist.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { $compile } from "./compile.js";
2
2
  import { Component } from "./component.js";
3
- import { $moveTo } from "./dom.js";
4
3
  import { __nextID } from "./idgen.js";
5
4
  import { $subWithID } from "./sub.js";
6
5
  const $klist = (src, tag, attribs, childCtor, keyFn) => $subWithID(
@@ -63,7 +62,7 @@ class KList extends Component {
63
62
  let next;
64
63
  const insert = async (item) => {
65
64
  if (cache.has(item.k)) {
66
- $moveTo(parent, item.v.el, next);
65
+ this.$moveTo(parent, item.v.el, next);
67
66
  next = item.v.el;
68
67
  } else {
69
68
  cache.set(item.k, item);
package/lazy.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare class $Lazy extends Component {
25
25
  protected observer: IntersectionObserver | undefined;
26
26
  protected inner: IComponent | undefined;
27
27
  constructor(tag: string, attribs: any, ctor: Fn0<Promise<ComponentLike>>, opts?: IntersectionObserverInit | undefined);
28
- mount(parent: Element, index?: NumOrElement | undefined): Promise<Element>;
28
+ mount(parent: ParentNode, index?: NumOrElement | undefined): Promise<Element>;
29
29
  unmount(): Promise<void>;
30
30
  }
31
31
  //# sourceMappingURL=lazy.d.ts.map
package/list.d.ts CHANGED
@@ -58,7 +58,7 @@ export declare class List<T> extends Component implements IMountWithState<T[]> {
58
58
  prev?: T[];
59
59
  items?: IComponent[];
60
60
  constructor(tag: string, attribs: any, ctor: Fn<T, IComponent>, equiv?: Predicate2<T>);
61
- mount(parent: Element, index: NumOrElement, state: T[]): Promise<Element>;
61
+ mount(parent: ParentNode, index: NumOrElement, state: T[]): Promise<Element>;
62
62
  unmount(): Promise<void>;
63
63
  update(curr: T[]): Promise<void>;
64
64
  }
package/object.d.ts CHANGED
@@ -80,7 +80,7 @@ export declare class $Object<T extends object, K extends Keys<T>> extends Compon
80
80
  protected obj: StreamObj<T, K>;
81
81
  protected inner?: IComponent;
82
82
  constructor(src: T, opts: Partial<StreamObjOpts<T, K>>, ctor: Fn<StreamObj<T, K>["streams"], Promise<ComponentLike>>);
83
- mount(parent: Element, index?: NumOrElement, state?: T): Promise<Element>;
83
+ mount(parent: ParentNode, index?: NumOrElement, state?: T): Promise<Element>;
84
84
  unmount(): Promise<void>;
85
85
  update(state: T): void;
86
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/rdom",
3
- "version": "0.14.0",
3
+ "version": "1.0.0",
4
4
  "description": "Lightweight, reactive, VDOM-less UI/DOM components with async lifecycle and @thi.ng/hiccup compatible",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -36,14 +36,14 @@
36
36
  "test": "bun test"
37
37
  },
38
38
  "dependencies": {
39
- "@thi.ng/api": "^8.9.15",
40
- "@thi.ng/checks": "^3.4.15",
41
- "@thi.ng/errors": "^2.4.9",
42
- "@thi.ng/hiccup": "^5.1.4",
43
- "@thi.ng/paths": "^5.1.56",
44
- "@thi.ng/prefixes": "^2.3.1",
45
- "@thi.ng/rstream": "^8.2.18",
46
- "@thi.ng/strings": "^3.7.6"
39
+ "@thi.ng/api": "^8.9.17",
40
+ "@thi.ng/checks": "^3.4.17",
41
+ "@thi.ng/errors": "^2.4.11",
42
+ "@thi.ng/hiccup": "^5.1.6",
43
+ "@thi.ng/paths": "^5.1.58",
44
+ "@thi.ng/prefixes": "^2.3.3",
45
+ "@thi.ng/rstream": "^8.2.20",
46
+ "@thi.ng/strings": "^3.7.8"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@microsoft/api-extractor": "^7.39.0",
@@ -122,9 +122,6 @@
122
122
  "./replace": {
123
123
  "default": "./replace.js"
124
124
  },
125
- "./scheduler": {
126
- "default": "./scheduler.js"
127
- },
128
125
  "./sub": {
129
126
  "default": "./sub.js"
130
127
  },
@@ -145,5 +142,5 @@
145
142
  ],
146
143
  "year": 2020
147
144
  },
148
- "gitHead": "775c664723cd87d6ac5909cedf91195317add287\n"
145
+ "gitHead": "417b5a7ea7bd54a3b4f086fe0fc2ce8e8933c9b2\n"
149
146
  }
package/promise.d.ts CHANGED
@@ -24,7 +24,7 @@ export declare class $Promise extends Component {
24
24
  protected error: Fn<Error, any>;
25
25
  inner?: IComponent;
26
26
  constructor(promise: Promise<ComponentLike>, error?: Fn<Error, any>);
27
- mount(parent: Element, index: NumOrElement): Promise<Element>;
27
+ mount(parent: ParentNode, index: NumOrElement): Promise<Element>;
28
28
  unmount(): Promise<void>;
29
29
  }
30
30
  //# sourceMappingURL=promise.d.ts.map
package/replace.d.ts CHANGED
@@ -35,10 +35,10 @@ import { Component } from "./component.js";
35
35
  */
36
36
  export declare const $replace: <T>(src: ISubscribable<T>) => IComponent<T>;
37
37
  export declare class Replace<T> extends Component implements IMountWithState<T> {
38
- protected parent?: Element;
38
+ protected parent?: ParentNode;
39
39
  protected inner?: IComponent<T>;
40
40
  protected index?: NumOrElement;
41
- mount(parent: Element, index: NumOrElement, val: T): Promise<Element>;
41
+ mount(parent: ParentNode, index: NumOrElement, val: T): Promise<Element>;
42
42
  unmount(): Promise<void>;
43
43
  update(val: T): Promise<void>;
44
44
  }
package/sub.d.ts CHANGED
@@ -42,7 +42,7 @@ export declare class $Sub<T = any> extends Subscription<T, T> {
42
42
  protected inner: IMountWithState<T | undefined>;
43
43
  el?: Element;
44
44
  constructor(inner: IMountWithState<T | undefined>, id?: string);
45
- mount(parent: Element, index?: NumOrElement): Promise<Element>;
45
+ mount(parent: ParentNode, index?: NumOrElement): Promise<Element>;
46
46
  unmount(): Promise<void>;
47
47
  update(x: T): void;
48
48
  next(x: T): void;
package/sub.js CHANGED
@@ -3,7 +3,6 @@ import { defSetterUnsafe } from "@thi.ng/paths/setter";
3
3
  import { __nextID } from "@thi.ng/rstream/idgen";
4
4
  import { Subscription } from "@thi.ng/rstream/subscription";
5
5
  import { $attribs } from "./dom.js";
6
- import { SCHEDULER } from "./scheduler.js";
7
6
  import { $wrapText } from "./wrap.js";
8
7
  function $sub(src, tag, attribs) {
9
8
  return src.subscribe(new $Sub(isString(tag) ? $wrapText(tag, attribs) : tag));
@@ -24,7 +23,6 @@ class $Sub extends Subscription {
24
23
  }
25
24
  async unmount() {
26
25
  this.unsubscribe();
27
- SCHEDULER.cancel(this);
28
26
  this.el = void 0;
29
27
  await this.inner.unmount();
30
28
  }
@@ -32,7 +30,8 @@ class $Sub extends Subscription {
32
30
  this.next(x);
33
31
  }
34
32
  next(x) {
35
- SCHEDULER.add(this, () => this.el && this.inner.update(x));
33
+ if (this.el)
34
+ this.inner.update(x);
36
35
  }
37
36
  }
38
37
  class $SubA extends Subscription {
@@ -44,11 +43,8 @@ class $SubA extends Subscription {
44
43
  setter;
45
44
  attr = {};
46
45
  next(a) {
47
- const $ = this.comp;
48
- SCHEDULER.add(
49
- $,
50
- () => $.el && $attribs($.el, this.setter(this.attr, a))
51
- );
46
+ if (this.comp.el)
47
+ $attribs(this.comp.el, this.setter(this.attr, a));
52
48
  }
53
49
  }
54
50
  export {
package/switch.d.ts CHANGED
@@ -86,11 +86,11 @@ export declare class Switch<T> extends Component implements IMountWithState<T> {
86
86
  protected error: Fn<Error, Promise<any>>;
87
87
  protected loader: Fn<T, Promise<any>>;
88
88
  protected val?: T;
89
- protected parent?: Element;
89
+ protected parent?: ParentNode;
90
90
  protected inner?: IComponent<T>;
91
91
  protected index?: NumOrElement;
92
92
  constructor(keyFn: Fn<T, NumOrString>, ctors: Record<NumOrString, Fn<T, Promise<any>>>, error?: Fn<Error, Promise<any>>, loader?: Fn<T, Promise<any>>);
93
- mount(parent: Element, index: NumOrElement, val: T): Promise<Element>;
93
+ mount(parent: ParentNode, index: NumOrElement, val: T): Promise<Element>;
94
94
  unmount(): Promise<void>;
95
95
  update(val: T): Promise<void>;
96
96
  }
package/wrap.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { $addChild, $el, $html, $remove, $text } from "./dom.js";
2
- import { SCHEDULER } from "./scheduler.js";
3
2
  const wrapper = (update) => (tag, attribs, body) => ({
4
3
  el: void 0,
5
4
  async mount(parent, index, state) {
@@ -12,7 +11,8 @@ const wrapper = (update) => (tag, attribs, body) => ({
12
11
  this.el = void 0;
13
12
  },
14
13
  update(body2) {
15
- SCHEDULER.add(this, () => this.el && update(this.el, body2));
14
+ if (this.el)
15
+ update(this.el, body2);
16
16
  }
17
17
  });
18
18
  const $wrapText = wrapper($text);
package/scheduler.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import type { Task, IScheduler } from "./api.js";
2
- /**
3
- * {@link IScheduler} implementation which queues component updates (or other
4
- * tasks) and then only processes them during next RAF cycle. Supports task
5
- * cancellation.
6
- *
7
- * @remarks
8
- * See {@link setScheduler} and {@link NullScheduler}.
9
- */
10
- export declare class RAFScheduler implements IScheduler {
11
- tasks: Map<any, Task[]>;
12
- raf: number;
13
- constructor();
14
- add(scope: any, fn: Task): void;
15
- cancel(scope: any): void;
16
- update(): void;
17
- }
18
- /**
19
- * Dummy (and default) {@link IScheduler} implementation which immediately
20
- * processes component updates.
21
- *
22
- * @remarks
23
- * See {@link setScheduler} and {@link RAFScheduler}.
24
- */
25
- export declare class NullScheduler implements IScheduler {
26
- add(_: any, fn: Task): void;
27
- cancel(): void;
28
- }
29
- export declare let SCHEDULER: IScheduler;
30
- /**
31
- * Sets rdom-global scheduler for component updates (and other tasks).
32
- *
33
- * @param s -
34
- */
35
- export declare const setScheduler: (s: IScheduler) => IScheduler;
36
- //# sourceMappingURL=scheduler.d.ts.map
package/scheduler.js DELETED
@@ -1,39 +0,0 @@
1
- class RAFScheduler {
2
- tasks;
3
- raf;
4
- constructor() {
5
- this.tasks = /* @__PURE__ */ new Map();
6
- this.raf = -1;
7
- }
8
- add(scope, fn) {
9
- const tasks = this.tasks.get(scope);
10
- tasks ? tasks.push(fn) : this.tasks.set(scope, [fn]);
11
- this.raf < 0 && (this.raf = requestAnimationFrame(this.update.bind(this)));
12
- }
13
- cancel(scope) {
14
- this.tasks.delete(scope);
15
- }
16
- update() {
17
- for (let tasks of this.tasks.values()) {
18
- for (let i = tasks.length; i-- > 0; tasks[i]())
19
- ;
20
- }
21
- this.tasks.clear();
22
- this.raf = -1;
23
- }
24
- }
25
- class NullScheduler {
26
- add(_, fn) {
27
- fn();
28
- }
29
- cancel() {
30
- }
31
- }
32
- let SCHEDULER = new NullScheduler();
33
- const setScheduler = (s) => SCHEDULER = s;
34
- export {
35
- NullScheduler,
36
- RAFScheduler,
37
- SCHEDULER,
38
- setScheduler
39
- };