Skip to content

Commit 815c3fc

Browse files
committed
Remove jsx components wrappers from core bundle
1 parent 3721465 commit 815c3fc

File tree

6 files changed

+204
-196
lines changed

6 files changed

+204
-196
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 23.0
4+
+ **Breaking:** Remove JSX component wrappers from core bundle.
5+
36
## 22.5
47
+ Add optional memory router parent.
58

scripts/bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ for (const moduleName of moduleNames) {
6666
}
6767

6868
const esBundle = await rollup({
69-
input: join(tscOut, moduleName, "index.js"),
69+
input: join(tscOut, moduleName, moduleName === "core" ? "core.js" : "index.js"),
7070
onwarn,
7171
external: id => {
7272
return id.startsWith("rvx-module:");

src/core/core.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export * from "./context.js";
2+
export * from "./element-builder.js";
3+
export * from "./element-common.js";
4+
export * from "./env.js";
5+
export * from "./event.js";
6+
export * from "./isolate.js";
7+
export * from "./lifecycle.js";
8+
export * from "./signals.js";
9+
export type * from "./types.js";
10+
export * from "./unique-id.js";
11+
export * from "./view.js";

src/core/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,2 @@
1-
export * from "./context.js";
2-
export * from "./element-builder.js";
3-
export * from "./element-common.js";
4-
export * from "./env.js";
5-
export * from "./event.js";
6-
export * from "./isolate.js";
7-
export * from "./lifecycle.js";
8-
export * from "./signals.js";
9-
export type * from "./types.js";
10-
export * from "./unique-id.js";
11-
export * from "./view.js";
1+
export * from "./core.js";
2+
export * from "./view-jsx.js";

src/core/view-jsx.ts

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
import { Expression, ExpressionResult } from "./signals.js";
2+
import { Component, Content, Falsy } from "./types.js";
3+
import { attachWhen, ForContentFn, forEach, IndexContentFn, indexEach, nest, View, when } from "./view.js";
4+
5+
/**
6+
* Watch an expression and render content from it's result.
7+
*
8+
* + If an error is thrown during initialization, the error is re-thrown.
9+
* + If an error is thrown during a signal update, the previously rendered content is kept in place and the error is re-thrown.
10+
* + Content returned from the component can be directly reused within the same `<Nest>` instance.
11+
*
12+
* See {@link nest} when not using JSX.
13+
*
14+
* @example
15+
* ```tsx
16+
* import { $, Nest } from "rvx";
17+
*
18+
* const count = $(0);
19+
*
20+
* <Nest watch={count}>
21+
* {count => {
22+
* switch (count) {
23+
* case 0: return <h1>Hello World!</h1>;
24+
* case 1: return "Something else...";
25+
* }
26+
* }}
27+
* </Nest>
28+
* ```
29+
*/
30+
export function Nest<T>(props: {
31+
/**
32+
* The expression to watch.
33+
*/
34+
watch: T;
35+
36+
/**
37+
* The component to render with the expression result.
38+
*
39+
* If the expression returns a component, null or undefined, this can be omitted.
40+
*/
41+
children: Component<ExpressionResult<T>>;
42+
} | {
43+
/**
44+
* The expression to watch.
45+
*/
46+
watch: Expression<Component | null | undefined>;
47+
}): View {
48+
return nest(props.watch, (props as any).children);
49+
}
50+
51+
/**
52+
* Render conditional content.
53+
*
54+
* + Content is only re-rendered if the expression result is not strictly equal to the previous one. If this behavior is undesired, use {@link Nest} instead.
55+
* + If an error is thrown by the expression or component during initialization, the error is re-thrown.
56+
* + If an error is thrown by the expression or component during a signal update, the previously rendered content is kept and the error is re-thrown.
57+
*
58+
* See {@link when} when not using JSX.
59+
*
60+
* @example
61+
* ```tsx
62+
* import { $, Show } from "rvx";
63+
*
64+
* const message = $<null | string>("Hello World!");
65+
*
66+
* <Show when={message} else={() => <>No message...</>}>
67+
* {value => <h1>{value}</h1>}
68+
* </Show>
69+
* ```
70+
*/
71+
export function Show<T>(props: {
72+
/**
73+
* The condition to watch.
74+
*/
75+
when: Expression<T | Falsy>;
76+
77+
/**
78+
* The component to render when the condition result is truthy.
79+
*/
80+
children: Component<T>;
81+
82+
/**
83+
* An optional component to render when the condition result is falsy.
84+
*/
85+
else?: Component;
86+
}): View {
87+
return when(props.when, props.children, props.else);
88+
}
89+
90+
/**
91+
* Render content for each unique value in an iterable.
92+
*
93+
* If an error is thrown while iterating or while rendering an item, the update is stopped as if the previous item was the last one and the error is re-thrown.
94+
*
95+
* See {@link forEach} when not using JSX.
96+
*
97+
* @example
98+
* ```tsx
99+
* import { $, For } from "rvx";
100+
*
101+
* const items = $([1, 2, 3]);
102+
*
103+
* <For each={items}>
104+
* {value => <li>{value}</li>}
105+
* </For>
106+
* ```
107+
*/
108+
export function For<T>(props: {
109+
/**
110+
* The expression to watch. Note, that signals accessed during iteration will also trigger updates.
111+
*/
112+
each: Expression<Iterable<T>>;
113+
114+
/**
115+
* The component to render for each unique value.
116+
*/
117+
children: ForContentFn<T>;
118+
}): View {
119+
return forEach(props.each, props.children);
120+
}
121+
122+
/**
123+
* Render content for each value in an iterable, keyed by index and value.
124+
*
125+
* If an error is thrown by iterating or by rendering an item, the update is stopped as if the previous item was the last one and the error is re-thrown.
126+
*
127+
* See {@link indexEach} when not using JSX.
128+
*
129+
* @example
130+
* ```tsx
131+
* import { $, Index } from "rvx";
132+
*
133+
* const items = $([1, 2, 3]);
134+
*
135+
* <Index each={items}>
136+
* {value => <li>{value}</li>}
137+
* </Index>
138+
* ```
139+
*/
140+
export function Index<T>(props: {
141+
/**
142+
* The expression to watch..
143+
*
144+
* Note, that signals accessed during iteration will also trigger updates.
145+
*/
146+
each: Expression<Iterable<T>>;
147+
148+
/**
149+
* The component to render for each value/index pair.
150+
*/
151+
children: IndexContentFn<T>;
152+
}): View {
153+
return indexEach(props.each, props.children);
154+
}
155+
156+
/**
157+
* Attach or detach content depending on an expression.
158+
*
159+
* Content is kept alive when detached.
160+
*
161+
* See {@link attachWhen} when not using JSX.
162+
*
163+
* @example
164+
* ```tsx
165+
* import { $, Attach } from "rvx";
166+
*
167+
* const showMessage = $(true);
168+
*
169+
* <Attach when={showMessage}>
170+
* <h1>Hello World!</h1>
171+
* </Attach>
172+
* ```
173+
*/
174+
export function Attach(props: {
175+
/**
176+
* The condition to watch.
177+
*/
178+
when: Expression<boolean>;
179+
180+
/**
181+
* The content to attach when the condition result is truthy.
182+
*/
183+
children?: Content;
184+
}): View {
185+
return attachWhen(props.when, props.children);
186+
}

0 commit comments

Comments
 (0)