solid-ctrl-flow 1.0.63 → 2.0.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/dist/index.d.ts +13 -34
- package/dist/index.mjs +18 -13
- package/dist/index.umd.js +17 -12
- package/package.json +1 -1
- package/readMe.md +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -10,22 +10,6 @@ export declare function Case(props: ParentProps<{
|
|
|
10
10
|
value: unknown;
|
|
11
11
|
}>): JSX.Element;
|
|
12
12
|
|
|
13
|
-
export declare function Case(props: ParentProps<{
|
|
14
|
-
pred(x: any): unknown;
|
|
15
|
-
}>): JSX.Element;
|
|
16
|
-
|
|
17
|
-
export declare function Case<T>(props: {
|
|
18
|
-
pred(x: any): T;
|
|
19
|
-
keyed?: false;
|
|
20
|
-
children(x: Accessor<NonNullable<T>>): JSX.Element;
|
|
21
|
-
}): JSX.Element;
|
|
22
|
-
|
|
23
|
-
export declare function Case<T>(props: {
|
|
24
|
-
pred(x: any): T;
|
|
25
|
-
keyed: true;
|
|
26
|
-
children(x: NonNullable<T>): JSX.Element;
|
|
27
|
-
}): JSX.Element;
|
|
28
|
-
|
|
29
13
|
/**
|
|
30
14
|
* Creates a slot that allows you to show a component outside of its parent.
|
|
31
15
|
* It works with arbitrary nesting.
|
|
@@ -44,7 +28,7 @@ export declare function Case<T>(props: {
|
|
|
44
28
|
* </e.Source>
|
|
45
29
|
* </div>
|
|
46
30
|
* </e.Joint>
|
|
47
|
-
*
|
|
31
|
+
* </>
|
|
48
32
|
* ```
|
|
49
33
|
* @param name Name to give to the context of the extractor
|
|
50
34
|
*/
|
|
@@ -110,32 +94,27 @@ export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, key
|
|
|
110
94
|
* return <>
|
|
111
95
|
* <Switch>
|
|
112
96
|
* <Match when={SOMETHING}>
|
|
113
|
-
*
|
|
97
|
+
* Random condition
|
|
114
98
|
* </Match>
|
|
115
|
-
* <On value={1}>
|
|
116
|
-
* <Case value=
|
|
117
|
-
*
|
|
118
|
-
* </Case>
|
|
119
|
-
* <Case pred={x => x === 2}>
|
|
120
|
-
* FALSE_WITH_PREDICATE
|
|
99
|
+
* <On value={1} onCompare={(a, b) => a == b}>
|
|
100
|
+
* <Case value="1">
|
|
101
|
+
* True because the comparator has been overridden
|
|
121
102
|
* </Case>
|
|
122
|
-
* <Case
|
|
123
|
-
*
|
|
124
|
-
* </Case>
|
|
125
|
-
* <Case keyed pred={x => x.innerValue}>
|
|
126
|
-
* {x => <>THRUTHY KEYED VALUE {x}</>}
|
|
103
|
+
* <Case value={2}>
|
|
104
|
+
* False
|
|
127
105
|
* </Case>
|
|
128
106
|
* </On>
|
|
129
107
|
* <Match when>
|
|
130
|
-
*
|
|
108
|
+
* Default
|
|
131
109
|
* </Match>
|
|
132
110
|
* </Switch>
|
|
133
|
-
*
|
|
111
|
+
* </>
|
|
134
112
|
* ```
|
|
135
113
|
*/
|
|
136
|
-
export declare
|
|
137
|
-
value:
|
|
138
|
-
|
|
114
|
+
export declare function On<T>(props: ParentProps<{
|
|
115
|
+
value: T;
|
|
116
|
+
onCompare?(a: unknown, b: T): boolean;
|
|
117
|
+
}>): JSX.Element;
|
|
139
118
|
|
|
140
119
|
/**
|
|
141
120
|
* Executes {@link f} with the provided value for the specified {@link Context}.
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMemo, splitProps, untrack, createRoot, getOwner, createComponent, Show, createContext, useContext, onCleanup, For,
|
|
1
|
+
import { createMemo, splitProps, untrack, createRoot, getOwner, createComponent, Show, createContext, useContext, onCleanup, For, createSelector, equalFn, Match } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
function memoProps(obj, keys = Reflect.ownKeys(obj), equals = false) {
|
|
4
4
|
const out = {};
|
|
@@ -159,21 +159,26 @@ function createInfo(props) {
|
|
|
159
159
|
const ctx = createContext(void 0, {
|
|
160
160
|
name: "on-case"
|
|
161
161
|
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
function On(props) {
|
|
163
|
+
const memo = memoProps(props);
|
|
164
|
+
const selector = createSelector(() => memo.value, (a, b) => (memo.onCompare ?? equalFn)(a, b));
|
|
165
|
+
return createComponent(ctx.Provider, {
|
|
166
|
+
value: selector,
|
|
167
|
+
get children() {
|
|
168
|
+
return props.children;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
168
172
|
function Case(props) {
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
|
|
172
|
-
return createComponent(Match, mergeProps({
|
|
173
|
+
const selector = useContext(ctx);
|
|
174
|
+
return createComponent(Match, {
|
|
173
175
|
get when() {
|
|
174
|
-
return
|
|
176
|
+
return selector(props.value);
|
|
177
|
+
},
|
|
178
|
+
get children() {
|
|
179
|
+
return props.children;
|
|
175
180
|
}
|
|
176
|
-
}
|
|
181
|
+
});
|
|
177
182
|
}
|
|
178
183
|
function SameContext(props) {
|
|
179
184
|
return createMemo(() => {
|
package/dist/index.umd.js
CHANGED
|
@@ -161,21 +161,26 @@
|
|
|
161
161
|
const ctx = solidJs.createContext(void 0, {
|
|
162
162
|
name: "on-case"
|
|
163
163
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
function On(props) {
|
|
165
|
+
const memo = memoProps(props);
|
|
166
|
+
const selector = solidJs.createSelector(() => memo.value, (a, b) => (memo.onCompare ?? solidJs.equalFn)(a, b));
|
|
167
|
+
return solidJs.createComponent(ctx.Provider, {
|
|
168
|
+
value: selector,
|
|
169
|
+
get children() {
|
|
170
|
+
return props.children;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
170
174
|
function Case(props) {
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
|
|
174
|
-
return solidJs.createComponent(solidJs.Match, solidJs.mergeProps({
|
|
175
|
+
const selector = solidJs.useContext(ctx);
|
|
176
|
+
return solidJs.createComponent(solidJs.Match, {
|
|
175
177
|
get when() {
|
|
176
|
-
return
|
|
178
|
+
return selector(props.value);
|
|
179
|
+
},
|
|
180
|
+
get children() {
|
|
181
|
+
return props.children;
|
|
177
182
|
}
|
|
178
|
-
}
|
|
183
|
+
});
|
|
179
184
|
}
|
|
180
185
|
function SameContext(props) {
|
|
181
186
|
return solidJs.createMemo(() => {
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -59,7 +59,6 @@ return <>
|
|
|
59
59
|
<On value={value}>
|
|
60
60
|
<Case value={1}>One</Case>
|
|
61
61
|
<Case value={2}>Two</Case>
|
|
62
|
-
<Case pred={x => `${x}`.length === 3}>Long</Case>
|
|
63
62
|
</On>
|
|
64
63
|
<Match when>Default</Match>
|
|
65
64
|
</Switch>
|
|
@@ -72,7 +71,6 @@ return <>
|
|
|
72
71
|
<Switch>
|
|
73
72
|
<Match when={value === 1}>One</Match>
|
|
74
73
|
<Match when={value === 2}>Two</Match>
|
|
75
|
-
<Match when={`${value}`.length === 3}>Long</Match>
|
|
76
74
|
<Match when>Default</Match>
|
|
77
75
|
</Switch>
|
|
78
76
|
</>
|