meowjsx 0.1.0 → 0.1.1-alpha.1
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/JSON.md +7 -7
- package/README.md +105 -116
- package/dist/src/reactive.d.ts +6 -0
- package/dist/src/reactive.js +92 -0
- package/dist/src/runtime.d.ts +1 -1
- package/dist/src/runtime.js +1 -1
- package/dist/web/strategy.js +4 -3
- package/package.json +6 -1
package/JSON.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# JSON
|
|
1
|
+
# JSON description entry
|
|
2
2
|
|
|
3
|
-
`meowjsx/json`
|
|
3
|
+
`meowjsx/json` builds ordinary MeowJSX VNodes from finite JSON descriptions, using the existing runtime, Context, Signal, components and renderer lifecycle; the core root entry does not import JSON or the DOM back.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
import { createJsonView, defineJsonComponent, jsonSchema, parseJsonView } from "meowjsx/json";
|
|
@@ -23,12 +23,12 @@ const description = parseJsonView(
|
|
|
23
23
|
const child = createJsonView(description, { catalog, bindings: new Map([["label", text]]) });
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Nodes support strings, finite numbers, booleans, null, node arrays, and `{component, props?, children?}`. `component` must be an exact name in the host catalog; arbitrary HTML tags, raw HTML, refs, code, dynamic imports, expressions or object paths are not provided. A binding in a description has the exclusive shape `{$binding:"exact name"}`, and an action has `{$action:"exact name"}`. Names are looked up only as exact Map keys; dots and paths are not parsed, and no external permissions are granted.
|
|
27
27
|
|
|
28
|
-
`parseJsonView`
|
|
28
|
+
`parseJsonView` only validates, copies and freezes data; it does not execute components, actions, event projections, Signal getters or runtime hooks. `createJsonView` then validates against the given catalog, binds the host's read-only Signals and real functions, and constructs VNodes; mounting and unmounting are still managed by the original renderer. Action arguments are validated by the finite schema in metadata; the host may provide a trusted `mapArgs` in metadata to project native events into explicit arguments, while JSON cannot provide executable code. The callback's original return value is preserved.
|
|
29
29
|
|
|
30
|
-
`jsonSchema`
|
|
30
|
+
`jsonSchema` supports string/number/boolean/enum/array/object/optional/data/union, and description and validation share these definitions. Object fields are strict, and a union must match one complete branch; `data()` only promises a pure JsonValue and does not claim through generics that a complex business type has been validated. Ordinary fields named constructor, $binding or $action inside data are still data and are not recursively interpreted as controls. If a prop's outermost value happens to be an exclusive reference marker, it is kept as a reference; when that literal object is needed, the host binding provides it rather than an additional escape DSL.
|
|
31
31
|
|
|
32
|
-
`defineJsonComponent`
|
|
32
|
+
`defineJsonComponent` statically associates finite metadata with the original component's Props and excludes arbitrary index fields of open Props; it does not reflect TS types automatically and does not claim that a whole-component schema exists. A concrete component library must state its supported set explicitly. `describeJsonCatalog` and `describeJsonSchema` output the finite description from the same metadata and do not maintain a separate schema. Functions, File, class instances, accessors, circular references, sparse arrays and non-finite numbers are not JSON data; the host is still responsible for network, permissions, persistence and the real data source.
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
Value metadata may provide a literal `default` that is validated against the same schema and copied and frozen, filled in only when the description omits that property; false, 0 and the empty string are not treated as missing. It does not execute actions, bindings or callbacks, and does not change the requirement that an explicit value for that property still matches the schema.
|
package/README.md
CHANGED
|
@@ -2,64 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
## Render-tree context
|
|
4
4
|
|
|
5
|
-
`createContext(defaultValue)`
|
|
6
|
-
`<Context.Provider value={value}>…</Context.Provider>`
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
`
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
不建立额外 dirty 集合或微任务。此回调抛错走 renderer 的 `onError(error, "async")`,不回滚
|
|
52
|
-
已发生的渲染;未提供错误出口则异步抛出。
|
|
53
|
-
|
|
54
|
-
工具可设置 `observer.roots`,按 child 对象引用限定观察子树;省略时观察整棵渲染树,
|
|
55
|
-
空数组时不观察实例。进入每个根后,首层组件的 `parent` 为 `null`,外层容器仍正常渲染、
|
|
56
|
-
传递 context 和执行 lifecycle,但不进入观察投影。根可为 VNode、Signal、Promise 或
|
|
57
|
-
AsyncIterable,延迟输出继续使用该范围。调用方若把内容数组展开交给容器,应传入其中的
|
|
58
|
-
实际 child 引用。此范围不增加组件调用,不影响 runtime hooks 或组件替换。
|
|
59
|
-
|
|
60
|
-
多消费者使用 `createComponentObservation<TNode>({ roots?, onError? })`,而不是各自复制
|
|
61
|
-
实例 Map。它返回 `observer`、`read(root?)`、`subscribe(listener, { root? })` 和 `dispose()`。
|
|
62
|
-
将 `observer` 接入 renderer 后,先订阅再读取即可取得当前状态和后续失效通知:
|
|
5
|
+
`createContext(defaultValue)` returns a typed Context and a `Provider` component.
|
|
6
|
+
`<Context.Provider value={value}>…</Context.Provider>` does not create a host node; descendant components read the nearest
|
|
7
|
+
ancestor value with `useContext(Context)` during synchronous render, and get the default when there is no Provider.
|
|
8
|
+
An explicitly provided `undefined` is still a value and does not fall back to the default. Siblings, independent root nodes and runtimes do not share environment.
|
|
9
|
+
|
|
10
|
+
Environment follows render-tree traversal, not the location where the VNode was created. Pre-created VNodes, arrays, host wrapper layers and subtrees replaced later by a Signal use the environment captured in the current area; deferred mounting of Promises and AsyncIterables preserves it as well.
|
|
11
|
+
Synchronous HTML output follows the same ancestor rule, but still does not support Promise / AsyncIterable content and throws when it encounters them.
|
|
12
|
+
|
|
13
|
+
`useContext` reads environment only during the component's synchronous execution. Event handlers and code after `await` must use the value captured in render beforehand; do not treat it as asynchronous local storage. Provider does not add whole-tree re-render or dependency tracking; to share a dynamic value, pass a Signal object as the value and let consumers use the existing Signal binding. Replacing a Provider's ordinary value does not automatically re-run already mounted descendants. Context's internal scope is passed by the renderer and users must not modify it.
|
|
14
|
+
|
|
15
|
+
`RuntimePlugin.resolveComponent({ component, props, runtime })` can select a replacement function before the component is called.
|
|
16
|
+
It is called in the order `pre`, normal, `post`, and within each group's registration order; the first non-`undefined` result wins, and returning the original function also stops resolution; the result is not resolved recursively. Selection happens before the lifecycle scope is created, and the selected component uses its own contract, parts and cleanup logic while the original component does not execute. `props` is a read-only typed view and does not copy or freeze the object.
|
|
17
|
+
|
|
18
|
+
This hook belongs to the execution runtime: pre-created VNodes, Signal/Promise deferred mounts and synchronous HTML all apply. The cleanup returned by `runtime.use()` unmounts rules and does not rewrite already mounted instances; other runtimes are unaffected.
|
|
19
|
+
It does not intercept module side effects or direct function calls, and does not change the meaning of the `create` / `render` hooks.
|
|
20
|
+
|
|
21
|
+
## Development metadata and instance observation
|
|
22
|
+
|
|
23
|
+
Component functions may carry `metadata?: ComponentMetadata`. `ComponentMetadata` is an open type-extension interface; development tools register their own namespaces through declaration merging, and core does not interpret or read their tool fields.
|
|
24
|
+
Both `Component<Props>` and the value returned by `defineComponent` preserve this constraint, and ordinary functions can use
|
|
25
|
+
`satisfies ComponentMetadata` to check assignment. Metadata is not part of props or component runtime options.
|
|
26
|
+
|
|
27
|
+
`runtime.createRenderer(strategy, { observer })` enables target-neutral instance observation:
|
|
28
|
+
`onComponent(instance)` reports creation, `onUnmount(instance)` reports unmounting; the optional
|
|
29
|
+
`onNode(instance, node, mounted)` reports node-association changes. An instance includes this renderer's `id`,
|
|
30
|
+
`parent`, the original function `originalComponent`, the actually executed function `component`, and a live read-only `nodes` collection.
|
|
31
|
+
The collection includes host and text output of that instance and its descendants, excluding internal markers; Signal, Promise and AsyncIterable updates keep the current associations.
|
|
32
|
+
Arrays and host tags do not add component levels, and direct function calls do not create component instances.
|
|
33
|
+
|
|
34
|
+
Built-in Fragment and Context Provider report `semantic` as `fragment` or
|
|
35
|
+
`context-provider` according to their actual executed function identity, not by name guessing. Replaced components use the selected function's semantic identity and metadata.
|
|
36
|
+
Observation adds no host wrapper layers; when disabled, no instance or node index is created. Callbacks run synchronously, and a throw is handled as a mount or cleanup failure; tools should handle diagnostics at their own boundary. Instances are removed from the tool projection after unmount, and `id` is not used to locate instances across runs.
|
|
37
|
+
|
|
38
|
+
The optional `onFlush(changed)` merges instance-invalidation notices in a microtask, covering component mount/unmount, node associations and updates to mounted host Signal props; exceptions and rollbacks also notify instances whose current facts may have changed. `changed` uses real instance
|
|
39
|
+
identity and includes instances unloaded in this round; it is not a successful-commit record. The set is cleared before the callback runs, and new changes caused by the callback go into the
|
|
40
|
+
next round without recursive delivery. It does not mean DOM layout, paint, all asynchronous work or application readiness; without this callback,
|
|
41
|
+
no additional dirty set or microtask is established. A throw from this callback goes through the renderer's `onError(error, "async")` and does not roll back
|
|
42
|
+
rendering that already happened; if no error outlet is provided, it is thrown asynchronously.
|
|
43
|
+
|
|
44
|
+
Tools can set `observer.roots` to limit the observed subtree by child object reference; when omitted the whole render tree is observed, and an empty array observes no instances. After entering each root, the first-level component's `parent` is `null`; outer containers still render normally,
|
|
45
|
+
pass context and run lifecycle, but do not enter the observation projection. A root may be a VNode, Signal, Promise or
|
|
46
|
+
AsyncIterable, and deferred output continues to use that scope. If the caller expands a content array into a container, it should pass the actual child references inside it. This scope adds no component calls and does not affect runtime hooks or component replacement.
|
|
47
|
+
|
|
48
|
+
Multiple consumers use `createComponentObservation<TNode>({ roots?, onError? })` instead of each copying
|
|
49
|
+
its own instance Map. It returns `observer`, `read(root?)`, `subscribe(listener, { root? })` and `dispose()`.
|
|
50
|
+
After wiring `observer` into the renderer, subscribe first and then read to obtain the current state and subsequent invalidation notices:
|
|
63
51
|
|
|
64
52
|
```ts
|
|
65
53
|
const observation = createComponentObservation<HostNode>({ onError: reportObserverError });
|
|
@@ -68,70 +56,67 @@ const unsubscribe = observation.subscribe(() => inspect(observation.read()));
|
|
|
68
56
|
const current = observation.read();
|
|
69
57
|
```
|
|
70
58
|
|
|
71
|
-
`read`
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
缺少该出口或出口再次抛错时异步报错,不静默吞错。
|
|
59
|
+
`read` returns a copy of the current instance-member array; the instance `nodes` is still the renderer-owned live collection; it is not
|
|
60
|
+
an immutable historical snapshot. `root` is the real instance object and includes itself and its descendants; reading an unmounted root is empty. Changes inside the root and ancestor changes can both invalidate subscriptions; notification may be conservative and does not promise a precise layout-impact set. Subscriptions have no implicit first replay;
|
|
61
|
+
delivery uses a snapshot of the subscriber list and re-checks validity before calling, so subscriptions cancelled in this round no longer run, and newly added
|
|
62
|
+
subscriptions begin with later notifications. A throwing consumer does not block other consumers; the error goes to the observation center's `onError`;
|
|
63
|
+
if that outlet is missing or throws again, the error is reported asynchronously rather than silently swallowed.
|
|
77
64
|
|
|
78
|
-
`dispose`
|
|
79
|
-
renderer
|
|
80
|
-
|
|
81
|
-
时读取并固定,适用于工具在创建前设置真实 child;不是运行时动态切换入口。纯宿主或文本根
|
|
82
|
-
没有组件实例,外部 DOM/样式、字体加载和浏览器尺寸变化也不属于该观察合同。
|
|
65
|
+
`dispose` only stops observation and clears the projection; it does not unmount the view. Afterwards `read` is empty and `subscribe` rejects; late notifications
|
|
66
|
+
from an existing renderer are ignored. Usually one observation center is attached to one renderer; the implementation stores by instance identity and does not overwrite because different renderers have the same numeric id. `roots` may use a getter, but the scope is read and fixed when the renderer is created, suitable for tools that set the real child before creation; it is not a runtime dynamic-switch entry. Purely host or text roots
|
|
67
|
+
have no component instances, and external DOM/styles, font loading and browser size changes also do not belong to this observation contract.
|
|
83
68
|
|
|
84
|
-
MeowJSX
|
|
85
|
-
|
|
86
|
-
`createRenderer()
|
|
69
|
+
MeowJSX core: the JSX/VNode factory, Signal/batch/effect, component and part contracts, shadow/plugin/theme
|
|
70
|
+
contracts, lifecycle and context, and the target-neutral renderer seam (`RenderStrategy<TNode>` /
|
|
71
|
+
`createRenderer()`). Core does not know the target platform.
|
|
87
72
|
|
|
88
73
|
```text
|
|
89
|
-
JSX
|
|
74
|
+
JSX source / component logic
|
|
90
75
|
│
|
|
91
|
-
meowjsx
|
|
92
|
-
└─→ meowjsx/web
|
|
76
|
+
meowjsx (this package: core + JSX contract)
|
|
77
|
+
└─→ meowjsx/web the same package's DOM / event / HTML / mount modules
|
|
93
78
|
```
|
|
94
79
|
|
|
95
|
-
##
|
|
80
|
+
## Exports
|
|
96
81
|
|
|
97
|
-
-
|
|
98
|
-
`createRuntime
|
|
99
|
-
`createThemePlugin
|
|
100
|
-
- `./renderer
|
|
101
|
-
`RendererOptions
|
|
102
|
-
render
|
|
103
|
-
- `./jsx-runtime
|
|
104
|
-
- `./jsx-dev-runtime
|
|
105
|
-
- `./web
|
|
106
|
-
- `./json
|
|
107
|
-
- `Runtime.targetHooks
|
|
108
|
-
|
|
82
|
+
- `.`, `./runtime`: `h`, `Fragment`, `raw`, `part`, `signal`/`batch`/`mapSignal`/`derived`,
|
|
83
|
+
`createRuntime`, `defaultRuntime`, `defineComponent`, `defineShadow`,
|
|
84
|
+
`createThemePlugin`, plus VNode/Signal/contract types.
|
|
85
|
+
- `./renderer`: `RenderStrategy<TNode>`, `createRenderer()`, `Renderer`/`Rendered`/
|
|
86
|
+
`RendererOptions`, `ComponentObserver`/`ObservedComponent` and other target-seam types. `createRenderer()` injects component lifecycle,
|
|
87
|
+
render hooks, overrides and `key`/`componentPart` identity; the target only implements node and attribute placement.
|
|
88
|
+
- `./jsx-runtime`: `jsx`/`jsxs`/`jsxDEV`/`Fragment`.
|
|
89
|
+
- `./jsx-dev-runtime`: the `jsxDEV`/`Fragment` needed by development automatic JSX, reusing the same implementation.
|
|
90
|
+
- `./web`: DOM mount, static HTML, Web shadow, instance-observation sources and skeleton visual controls.
|
|
91
|
+
- `./json`: finite descriptions, host binding/action references, single-source metadata validation and catalog descriptions; see [JSON entry](JSON.md).
|
|
92
|
+
- `Runtime.targetHooks`: when the target owns the output path (Web's static HTML), reuse the runtime's
|
|
93
|
+
component calls, render hooks and override semantics instead of copying a set into the target.
|
|
109
94
|
|
|
110
|
-
core
|
|
111
|
-
`meowjsx/web
|
|
95
|
+
The core root has no `render`/`renderToHtml`: `render(node, Element)` and HTML serialization are imported from
|
|
96
|
+
`meowjsx/web`. The root does not import Web back; both use the same core module, and multiple explicit Runtimes can still be created independently.
|
|
112
97
|
|
|
113
|
-
##
|
|
98
|
+
## Invariant: core contains no platform
|
|
114
99
|
|
|
115
|
-
core
|
|
116
|
-
|
|
117
|
-
`dom` lib
|
|
100
|
+
The core source (including types) does not contain `document`, `window`, DOM `Element`/`HTMLElement`,
|
|
101
|
+
browser `Event`, CSS APIs or terminal APIs. `packages/meowjsx/tsconfig.core.json` checks the whole core under a configuration without the
|
|
102
|
+
`dom` lib and with `types: []`:
|
|
118
103
|
|
|
119
104
|
```sh
|
|
120
105
|
bun node_modules/typescript/bin/tsc -p packages/meowjsx/tsconfig.core.json
|
|
121
106
|
```
|
|
122
107
|
|
|
123
|
-
|
|
108
|
+
The command above runs from the repository root and only checks the DOM-free core group. The package's `bun run typecheck` runs core, renderer and Web configurations in order; the final Web group explicitly includes the DOM and is not equivalent to the DOM-free core-only check. `tsconfig.renderer.json` independently checks the target-neutral renderer seam, and behavior cases use a fake target.
|
|
124
109
|
|
|
125
|
-
`ShadowContext.element`
|
|
126
|
-
|
|
127
|
-
`ThemeStyle`
|
|
110
|
+
`ShadowContext.element` is the target-provided host handle, typed as generic `TNode` in core
|
|
111
|
+
(defaults to `unknown`); the Web module narrows it to a real element. Theme contracts (`Theme`/`ThemeRule`/
|
|
112
|
+
`ThemeStyle` and their merge rules) stay in core as planned; they carry values only and touch no style API.
|
|
128
113
|
|
|
129
|
-
##
|
|
114
|
+
## Verification
|
|
130
115
|
|
|
131
|
-
- `bun test packages/meowjsx/tests/unit
|
|
132
|
-
- `tests/types/`
|
|
116
|
+
- `bun test packages/meowjsx/tests/unit`: Signal, VNode, plugin, contracts, fake target seam and Web host tests.
|
|
117
|
+
- `tests/types/` checks core and Web type cases separately; the core type environment does not include the DOM.
|
|
133
118
|
|
|
134
|
-
## Web
|
|
119
|
+
## Web module
|
|
135
120
|
|
|
136
121
|
```ts
|
|
137
122
|
import { createRuntime, h } from "meowjsx";
|
|
@@ -142,19 +127,23 @@ const mounted = web.render(h("p", {}, "Hello"), document.querySelector("main")!)
|
|
|
142
127
|
mounted.unmount();
|
|
143
128
|
```
|
|
144
129
|
|
|
145
|
-
Web
|
|
146
|
-
`createSkeletonController`
|
|
147
|
-
|
|
148
|
-
`createWebRenderer(runtime)`
|
|
149
|
-
|
|
130
|
+
The Web source lives in `web/`, and DOM types only arrive through that entry. Static `renderToHtml` does not mount a DOM or run shadow;
|
|
131
|
+
`createSkeletonController` needs a real document and CSS Custom Highlight support only when called.
|
|
132
|
+
Importing the module creates the default Web renderer and observation Context; it does not install styles or listeners.
|
|
133
|
+
`createWebRenderer(runtime)` respects the components, themes and plugins already installed in that runtime; when an observation source is passed explicitly,
|
|
134
|
+
its lifecycle is managed by the consumer, and no global observation tree is created across renderers.
|
|
135
|
+
|
|
136
|
+
Public JS artifacts preserve module relationships: the root, runtime, automatic JSX and Web entries reference the same core.
|
|
137
|
+
Release builds must not copy a defaultRuntime, Context or reactive scheduler per entry.
|
|
138
|
+
|
|
139
|
+
## Derived signals
|
|
150
140
|
|
|
151
|
-
|
|
152
|
-
发布构建不能为每个入口复制一份 defaultRuntime、Context 或响应式调度器。
|
|
141
|
+
`derived(read)` is a read-only signal. `read` runs again when any signal it read changes, and subscribers hear the value when `Object.is` says it changed. `read` must not write signals. One source can also use `mapSignal`. A computation is not stored by writing another signal from `effect`.
|
|
153
142
|
|
|
154
|
-
##
|
|
143
|
+
## Keyed dynamic lists
|
|
155
144
|
|
|
156
|
-
`keyed(items, key, render)`
|
|
157
|
-
|
|
145
|
+
`keyed(items, key, render)` keeps rows with the same key holding the same components, nodes, Context and observation parent chain; an update only changes that row's read-only item Signal,
|
|
146
|
+
a deletion releases that row's lifecycle, and reordering moves the existing range. Whole-replacement semantics for plain arrays and Signals are unchanged.
|
|
158
147
|
|
|
159
148
|
```ts
|
|
160
149
|
const items = signal([{ id: "one", label: "First" }]);
|
|
@@ -170,7 +159,7 @@ const rows = keyed(
|
|
|
170
159
|
);
|
|
171
160
|
```
|
|
172
161
|
|
|
173
|
-
`render`
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
162
|
+
`render` constructs a Child and is not an extra lifecycle hook; when reading Signals inside a component, keep using the existing Signal properties or `mapSignal`.
|
|
163
|
+
Keys must be unique and must be strings or finite numbers; duplicate/invalid keys and new-row mount failures keep the original rows and values, and later valid updates still continue.
|
|
164
|
+
Target insert/remove failures provide no transactional rollback. Ordinary appends at either end do not move old rows; whether native focus survives arbitrary reordering depends on the target's move capability.
|
|
165
|
+
Static HTML reads the list once and does not subscribe or mount a DOM.
|
package/dist/src/reactive.d.ts
CHANGED
|
@@ -7,3 +7,9 @@ export declare function isPromiseLike<T = unknown>(value: unknown): value is Pro
|
|
|
7
7
|
export declare function isAsyncIterable<T = unknown>(value: unknown): value is AsyncIterable<T>;
|
|
8
8
|
export declare function unwrap<T>(value: MaybeSignal<T>): T;
|
|
9
9
|
export declare function mapSignal<T, M>(source: ReadableSignal<T>, map: (value: T) => M): ReadableSignal<M>;
|
|
10
|
+
/**
|
|
11
|
+
* Read-only signal. `read` runs again when any signal it touched changes.
|
|
12
|
+
* Subscribers are told only when `Object.is` sees a new value. `read` must not
|
|
13
|
+
* write signals; a cyclic read throws.
|
|
14
|
+
*/
|
|
15
|
+
export declare function derived<T>(read: () => T): ReadableSignal<T>;
|
package/dist/src/reactive.js
CHANGED
|
@@ -156,3 +156,95 @@ export function mapSignal(source, map) {
|
|
|
156
156
|
};
|
|
157
157
|
return mapped;
|
|
158
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Read-only signal. `read` runs again when any signal it touched changes.
|
|
161
|
+
* Subscribers are told only when `Object.is` sees a new value. `read` must not
|
|
162
|
+
* write signals; a cyclic read throws.
|
|
163
|
+
*/
|
|
164
|
+
export function derived(read) {
|
|
165
|
+
const listeners = new Set();
|
|
166
|
+
let cleanups = [];
|
|
167
|
+
let previous;
|
|
168
|
+
let ready = false;
|
|
169
|
+
let computing = false;
|
|
170
|
+
let queued = false;
|
|
171
|
+
const detach = () => {
|
|
172
|
+
for (const cleanup of cleanups)
|
|
173
|
+
cleanup();
|
|
174
|
+
cleanups = [];
|
|
175
|
+
};
|
|
176
|
+
const refresh = (notify) => {
|
|
177
|
+
if (computing) {
|
|
178
|
+
queued = true;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const dependencies = new Set();
|
|
182
|
+
const previousEffect = activeEffect;
|
|
183
|
+
activeEffect = {
|
|
184
|
+
dependencies,
|
|
185
|
+
subscriptions: [],
|
|
186
|
+
stopped: false,
|
|
187
|
+
scheduled: false,
|
|
188
|
+
};
|
|
189
|
+
computing = true;
|
|
190
|
+
let next;
|
|
191
|
+
try {
|
|
192
|
+
next = read();
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
activeEffect = previousEffect;
|
|
196
|
+
computing = false;
|
|
197
|
+
}
|
|
198
|
+
detach();
|
|
199
|
+
if (listeners.size > 0) {
|
|
200
|
+
cleanups = [...dependencies].map((source) => source.subscribe(() => refresh(true)));
|
|
201
|
+
}
|
|
202
|
+
const changed = !ready || !Object.is(previous, next);
|
|
203
|
+
previous = next;
|
|
204
|
+
ready = true;
|
|
205
|
+
if (notify && changed) {
|
|
206
|
+
for (const listener of Array.from(listeners))
|
|
207
|
+
listener(next);
|
|
208
|
+
}
|
|
209
|
+
if (queued) {
|
|
210
|
+
queued = false;
|
|
211
|
+
refresh(true);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const computed = {
|
|
215
|
+
get value() {
|
|
216
|
+
if (computing)
|
|
217
|
+
throw new Error("derived read is cyclic");
|
|
218
|
+
trackSignal(computed);
|
|
219
|
+
computing = true;
|
|
220
|
+
try {
|
|
221
|
+
return read();
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
computing = false;
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
subscribe(listener) {
|
|
228
|
+
const start = listeners.size === 0;
|
|
229
|
+
listeners.add(listener);
|
|
230
|
+
try {
|
|
231
|
+
if (start)
|
|
232
|
+
refresh(false);
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
listeners.delete(listener);
|
|
236
|
+
detach();
|
|
237
|
+
ready = false;
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
return () => {
|
|
241
|
+
listeners.delete(listener);
|
|
242
|
+
if (listeners.size === 0) {
|
|
243
|
+
detach();
|
|
244
|
+
ready = false;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
return computed;
|
|
250
|
+
}
|
package/dist/src/runtime.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { createContext, useContext, type Context, type ContextScope } from "./co
|
|
|
2
2
|
export { keyed, type KeyedChild } from "./keyed.js";
|
|
3
3
|
import type { Child, Cleanup, ComponentContract, ComponentRenderContext, ShadowDefinition, ShadowSetup, Component, ComponentPartRef, FragmentComponent, Props, Runtime, RuntimeOptions, RuntimePluginOption, VNode } from "./types.js";
|
|
4
4
|
export type { Child, Cleanup, Component, ComponentContract, ComponentMetadata, ComponentPartRef, ComponentRegistry, ComponentRegistryMap, ComponentRenderContext, CreateContext, CreateHook, Effect, ElementType, FragmentComponent, Key, LifecycleScope, MaybeSignal, MountResult, Props, ReadableSignal, RegisteredComponentName, RegisteredComponentPart, RenderContext, RenderHook, ResolveComponentContext, ResolveComponentHook, Runtime, RuntimeOptions, RuntimePlugin, RuntimePluginContext, RuntimePluginEnforce, RuntimePluginOption, RuntimePluginSetup, RuntimeRendererOptions, RuntimeTargetHooks, ShadowContext, ShadowDefinition, ShadowRegistry, ShadowSetup, Signal, StyleObject, StyleScalar, StyleValue, Theme, ThemeContext, ThemeRule, ThemeRules, ThemeStyle, VNode, WritableSignal, } from "./types.js";
|
|
5
|
-
export { batch, isAsyncIterable, isPromiseLike, isSignal, mapSignal, signal, unwrap, } from "./reactive.js";
|
|
5
|
+
export { batch, isAsyncIterable, isPromiseLike, derived, isSignal, mapSignal, signal, unwrap, } from "./reactive.js";
|
|
6
6
|
export { createLifecycleScope } from "./lifecycle.js";
|
|
7
7
|
export { createThemePlugin, styleText } from "./style.js";
|
|
8
8
|
export declare function defineComponent<PropsType extends object, Name extends string, Part extends string>(contract: ComponentContract<Name, Part>, render: (props: PropsType, context: ComponentRenderContext<Name, Part, PropsType>) => Child): Component<PropsType, Name, Part>;
|
package/dist/src/runtime.js
CHANGED
|
@@ -4,7 +4,7 @@ import { isContextProvider } from "./context.js";
|
|
|
4
4
|
import { createRenderer as createTargetRenderer, } from "./renderer.js";
|
|
5
5
|
import { addHook, createBaseVNode, createComponentContext, createComponentRegistry, createShadowRegistry, invokeComponent, removeHook, runCreateHooks, runRenderHooks, } from "./registry.js";
|
|
6
6
|
import { createLifecycleScope, disposeCleanups } from "./lifecycle.js";
|
|
7
|
-
export { batch, isAsyncIterable, isPromiseLike, isSignal, mapSignal, signal, unwrap, } from "./reactive.js";
|
|
7
|
+
export { batch, isAsyncIterable, isPromiseLike, derived, isSignal, mapSignal, signal, unwrap, } from "./reactive.js";
|
|
8
8
|
export { createLifecycleScope } from "./lifecycle.js";
|
|
9
9
|
export { createThemePlugin, styleText } from "./style.js";
|
|
10
10
|
function isRuntimePluginArray(option) {
|
package/dist/web/strategy.js
CHANGED
|
@@ -94,12 +94,13 @@ export function setDOMProperty(element, name, value) {
|
|
|
94
94
|
!name.startsWith("aria") &&
|
|
95
95
|
name in target) {
|
|
96
96
|
try {
|
|
97
|
-
target
|
|
98
|
-
|
|
97
|
+
if (Reflect.set(target, name, resolved))
|
|
98
|
+
return () => { };
|
|
99
99
|
}
|
|
100
100
|
catch {
|
|
101
|
-
//
|
|
101
|
+
// Some DOM setters reject values by throwing instead of returning false.
|
|
102
102
|
}
|
|
103
|
+
// Getter-only DOM properties must also fall through in non-strict bundles.
|
|
103
104
|
}
|
|
104
105
|
element.setAttribute(attributeName, String(resolved));
|
|
105
106
|
return () => { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meowjsx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -44,5 +44,10 @@
|
|
|
44
44
|
"types": "./dist/src/json/index.d.ts",
|
|
45
45
|
"import": "./dist/src/json/index.js"
|
|
46
46
|
}
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/lidessen/meowland.git",
|
|
51
|
+
"directory": "packages/meowjsx"
|
|
47
52
|
}
|
|
48
53
|
}
|