solid-ctrl-flow 2.2.5 → 4.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/dist/index.d.ts +8 -4
- package/dist/index.mjs +25 -25
- package/dist/index.umd.js +24 -24
- package/package.json +1 -1
- package/readMe.md +21 -21
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { splitProps } from 'solid-js';
|
|
|
9
9
|
/** Like a {@link Match} but gets the value from the closest {@link On} ancestor */
|
|
10
10
|
export declare function Case(props: ParentProps<{
|
|
11
11
|
value: unknown;
|
|
12
|
-
}>): JSX
|
|
12
|
+
}>): JSX;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Eventually wraps its content into a template if a certain condition is met.
|
|
@@ -57,11 +57,15 @@ export declare class Extractor {
|
|
|
57
57
|
Joint: (props: {
|
|
58
58
|
children?: JSX.Element;
|
|
59
59
|
}) => JSX.Element;
|
|
60
|
-
Fallback: () => JSX.Element;
|
|
61
60
|
Dest: (props: {
|
|
62
|
-
|
|
61
|
+
children?: JSX.Element;
|
|
63
62
|
}) => JSX.Element;
|
|
64
63
|
Source: (props: Info) => JSX.Element;
|
|
64
|
+
SameContextSource: (props: {
|
|
65
|
+
order?: number | undefined;
|
|
66
|
+
} & {
|
|
67
|
+
children?: JSX.Element;
|
|
68
|
+
}) => JSX.Element;
|
|
65
69
|
/**
|
|
66
70
|
* Returns the number of destinations available for the current {@link Extractor}.
|
|
67
71
|
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
@@ -121,7 +125,7 @@ export declare function memoProps<T, K extends readonly (keyof T)[]>(obj: T, key
|
|
|
121
125
|
export declare function On<T>(props: ParentProps<{
|
|
122
126
|
value: T;
|
|
123
127
|
onCompare?(a: unknown, b: T): boolean;
|
|
124
|
-
}>): JSX
|
|
128
|
+
}>): JSX;
|
|
125
129
|
|
|
126
130
|
/**
|
|
127
131
|
* Ordered linked list that allows for:
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createMemo, splitProps, untrack, createRoot, getOwner, createComponent, Show, createContext, useContext, createRenderEffect, on,
|
|
1
|
+
import { createMemo, splitProps, untrack, createRoot, getOwner, createComponent, Show, createContext, useContext, onCleanup, For, createRenderEffect, on, mergeProps, createSignal, createSelector, equalFn, Match } from "solid-js";
|
|
2
2
|
const NO_OP = () => {
|
|
3
3
|
};
|
|
4
4
|
function memoProps(obj, keys = Reflect.ownKeys(obj), equals = false) {
|
|
@@ -123,10 +123,11 @@ class Extractor {
|
|
|
123
123
|
name
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
+
ctx;
|
|
126
127
|
Joint = Joint.bind(this);
|
|
127
|
-
Fallback = Fallback.bind(this);
|
|
128
128
|
Dest = Dest.bind(this);
|
|
129
129
|
Source = Source.bind(this);
|
|
130
|
+
SameContextSource = SameContextSource.bind(this);
|
|
130
131
|
/**
|
|
131
132
|
* Returns the number of destinations available for the current {@link Extractor}.
|
|
132
133
|
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
@@ -146,41 +147,26 @@ function Joint(props) {
|
|
|
146
147
|
}
|
|
147
148
|
});
|
|
148
149
|
}
|
|
149
|
-
function Fallback() {
|
|
150
|
-
const _self$ = this;
|
|
151
|
-
const f = this.getDestCount;
|
|
152
|
-
return createComponent(Show, {
|
|
153
|
-
get when() {
|
|
154
|
-
return !f?.();
|
|
155
|
-
},
|
|
156
|
-
get children() {
|
|
157
|
-
return createComponent(_self$.Dest, {
|
|
158
|
-
hidden: true
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
150
|
function Dest(props) {
|
|
164
151
|
const state = useContext(this.ctx);
|
|
165
152
|
if (!state)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return;
|
|
170
|
-
onCleanup(() => state.shift(-1));
|
|
171
|
-
state.shift(1);
|
|
172
|
-
}));
|
|
153
|
+
return createMemo(() => props.children);
|
|
154
|
+
onCleanup(() => state.shift(-1));
|
|
155
|
+
state.shift(1);
|
|
173
156
|
return createComponent(For, {
|
|
174
157
|
get each() {
|
|
175
158
|
return [...state.sources];
|
|
176
159
|
},
|
|
160
|
+
get fallback() {
|
|
161
|
+
return props.children;
|
|
162
|
+
},
|
|
177
163
|
children: (x) => createMemo(() => x.children)
|
|
178
164
|
});
|
|
179
165
|
}
|
|
180
166
|
function Source(props) {
|
|
181
167
|
const state = useContext(this.ctx);
|
|
182
168
|
if (!state)
|
|
183
|
-
|
|
169
|
+
return [];
|
|
184
170
|
const {
|
|
185
171
|
sources
|
|
186
172
|
} = state;
|
|
@@ -202,7 +188,21 @@ function Source(props) {
|
|
|
202
188
|
sources.add(node, COMPARATOR);
|
|
203
189
|
state.force();
|
|
204
190
|
}));
|
|
205
|
-
|
|
191
|
+
}
|
|
192
|
+
function SameContextSource(props) {
|
|
193
|
+
const _self$ = this;
|
|
194
|
+
const [mine, other] = splitProps(props, ["children"]);
|
|
195
|
+
const owner = getOwner();
|
|
196
|
+
return createComponent(_self$.Source, mergeProps(other, {
|
|
197
|
+
get children() {
|
|
198
|
+
return createComponent(SameContext, {
|
|
199
|
+
owner,
|
|
200
|
+
get children() {
|
|
201
|
+
return mine.children;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}));
|
|
206
206
|
}
|
|
207
207
|
const ctx = createContext(void 0, {
|
|
208
208
|
name: "on-case"
|
package/dist/index.umd.js
CHANGED
|
@@ -126,10 +126,11 @@
|
|
|
126
126
|
name
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
+
ctx;
|
|
129
130
|
Joint = Joint.bind(this);
|
|
130
|
-
Fallback = Fallback.bind(this);
|
|
131
131
|
Dest = Dest.bind(this);
|
|
132
132
|
Source = Source.bind(this);
|
|
133
|
+
SameContextSource = SameContextSource.bind(this);
|
|
133
134
|
/**
|
|
134
135
|
* Returns the number of destinations available for the current {@link Extractor}.
|
|
135
136
|
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
@@ -149,41 +150,26 @@
|
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
152
|
}
|
|
152
|
-
function Fallback() {
|
|
153
|
-
const _self$ = this;
|
|
154
|
-
const f = this.getDestCount;
|
|
155
|
-
return solidJs.createComponent(solidJs.Show, {
|
|
156
|
-
get when() {
|
|
157
|
-
return !f?.();
|
|
158
|
-
},
|
|
159
|
-
get children() {
|
|
160
|
-
return solidJs.createComponent(_self$.Dest, {
|
|
161
|
-
hidden: true
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
153
|
function Dest(props) {
|
|
167
154
|
const state = solidJs.useContext(this.ctx);
|
|
168
155
|
if (!state)
|
|
169
|
-
|
|
170
|
-
solidJs.
|
|
171
|
-
|
|
172
|
-
return;
|
|
173
|
-
solidJs.onCleanup(() => state.shift(-1));
|
|
174
|
-
state.shift(1);
|
|
175
|
-
}));
|
|
156
|
+
return solidJs.createMemo(() => props.children);
|
|
157
|
+
solidJs.onCleanup(() => state.shift(-1));
|
|
158
|
+
state.shift(1);
|
|
176
159
|
return solidJs.createComponent(solidJs.For, {
|
|
177
160
|
get each() {
|
|
178
161
|
return [...state.sources];
|
|
179
162
|
},
|
|
163
|
+
get fallback() {
|
|
164
|
+
return props.children;
|
|
165
|
+
},
|
|
180
166
|
children: (x) => solidJs.createMemo(() => x.children)
|
|
181
167
|
});
|
|
182
168
|
}
|
|
183
169
|
function Source(props) {
|
|
184
170
|
const state = solidJs.useContext(this.ctx);
|
|
185
171
|
if (!state)
|
|
186
|
-
|
|
172
|
+
return [];
|
|
187
173
|
const {
|
|
188
174
|
sources
|
|
189
175
|
} = state;
|
|
@@ -205,7 +191,21 @@
|
|
|
205
191
|
sources.add(node, COMPARATOR);
|
|
206
192
|
state.force();
|
|
207
193
|
}));
|
|
208
|
-
|
|
194
|
+
}
|
|
195
|
+
function SameContextSource(props) {
|
|
196
|
+
const _self$ = this;
|
|
197
|
+
const [mine, other] = solidJs.splitProps(props, ["children"]);
|
|
198
|
+
const owner = solidJs.getOwner();
|
|
199
|
+
return solidJs.createComponent(_self$.Source, solidJs.mergeProps(other, {
|
|
200
|
+
get children() {
|
|
201
|
+
return solidJs.createComponent(SameContext, {
|
|
202
|
+
owner,
|
|
203
|
+
get children() {
|
|
204
|
+
return mine.children;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}));
|
|
209
209
|
}
|
|
210
210
|
const ctx = solidJs.createContext(void 0, {
|
|
211
211
|
name: "on-case"
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -94,7 +94,7 @@ return <>
|
|
|
94
94
|
</e.Joint>
|
|
95
95
|
</>
|
|
96
96
|
```
|
|
97
|
-
|
|
97
|
+
If a `Extractor.Dest` has no `Extractor.Source` to render (Or it isn't inside a `Extractor.Joint`), it will render whatever you pass inside the `children` attribute
|
|
98
98
|
<br />
|
|
99
99
|
Componets from different `Extractor`s don't "talk" to each other and there can be more than one source and destinations:
|
|
100
100
|
```tsx
|
|
@@ -117,7 +117,7 @@ return <>
|
|
|
117
117
|
<a.Dest />
|
|
118
118
|
<b.Joint>
|
|
119
119
|
{/* No source */}
|
|
120
|
-
<b.Dest
|
|
120
|
+
<b.Dest>fb</b.Dest>
|
|
121
121
|
<c.Joint>
|
|
122
122
|
3
|
|
123
123
|
{/* Double destination */}
|
|
@@ -145,7 +145,7 @@ return <>
|
|
|
145
145
|
</a.Joint>
|
|
146
146
|
</>
|
|
147
147
|
```
|
|
148
|
-
The output of this code is ***1***, ***5***, 3, ***1***, ***5***, 4, 0, 2, ***8***, 7, ***8***.
|
|
148
|
+
The output of this code is ***1***, ***5***, ~~fb~~, 3, ***1***, ***5***, 4, 0, 2, ***8***, 7, ***8***.
|
|
149
149
|
<br />
|
|
150
150
|
You can detect the number of destinations available for a given extractor through `Extractor.getDestCount()`
|
|
151
151
|
```tsx
|
|
@@ -196,26 +196,26 @@ return <>
|
|
|
196
196
|
</e.Joint>
|
|
197
197
|
</>
|
|
198
198
|
```
|
|
199
|
-
You can
|
|
199
|
+
You can use `Extractor.SameContextSource` to automate the process of using a `SameContext` inside a `Extractor.Source`. When in doubt, use `Extractor.SameContextSource` instead of `Extractor.Source`
|
|
200
200
|
```tsx
|
|
201
|
+
const e = new Extractor(), ctx = createContext(1);
|
|
201
202
|
return <>
|
|
202
|
-
<
|
|
203
|
-
<
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
<someExtractor.Fallback />
|
|
203
|
+
<e.Joint>
|
|
204
|
+
<div>
|
|
205
|
+
{/* This will contain "1" and "3" */}
|
|
206
|
+
<e.Dest />
|
|
207
|
+
</div>
|
|
208
|
+
<ctx.Provider value={2}>
|
|
209
|
+
<div>
|
|
210
|
+
{/* This will contain "2" and "3" */}
|
|
211
|
+
<e.Dest />
|
|
212
|
+
</div>
|
|
213
|
+
<ctx.Provider value={3}>
|
|
214
|
+
<e.Source>{useContext(ctx)}</e.Source>
|
|
215
|
+
<e.SameContextSource>{useContext(ctx)}</e.SameContextSource>
|
|
216
|
+
</ctx.Provider>
|
|
217
|
+
</ctx.Provider>
|
|
218
|
+
</e.Joint>
|
|
219
219
|
</>
|
|
220
220
|
```
|
|
221
221
|
|