solid-ctrl-flow 6.0.0 → 6.1.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 +17 -8
- package/dist/index.mjs +32 -10
- package/dist/index.umd.js +31 -9
- package/package.json +1 -1
- package/readMe.md +2 -0
package/dist/index.d.ts
CHANGED
|
@@ -55,17 +55,23 @@ export declare class Extractor {
|
|
|
55
55
|
constructor(name?: string);
|
|
56
56
|
readonly ctx: Context<State | undefined>;
|
|
57
57
|
Joint: (props: {
|
|
58
|
-
children?: JSX
|
|
59
|
-
}) => JSX
|
|
58
|
+
children?: JSX;
|
|
59
|
+
}) => JSX;
|
|
60
60
|
Dest: (props: {
|
|
61
|
-
children?: JSX
|
|
62
|
-
}) => JSX
|
|
63
|
-
Source: (props: Info) => JSX
|
|
61
|
+
children?: JSX;
|
|
62
|
+
}) => JSX;
|
|
63
|
+
Source: (props: Info) => JSX;
|
|
64
64
|
SameContextSource: (props: {
|
|
65
65
|
order?: number | undefined;
|
|
66
66
|
} & {
|
|
67
|
-
children?: JSX
|
|
68
|
-
}) => JSX
|
|
67
|
+
children?: JSX;
|
|
68
|
+
}) => JSX;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the number of sources available for the current {@link Extractor}.
|
|
71
|
+
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
72
|
+
* If the current {@link Owner} is NOT under a {@link Joint}, it will return `undefined`
|
|
73
|
+
*/
|
|
74
|
+
get getSourceCount(): (() => number) | undefined;
|
|
69
75
|
/**
|
|
70
76
|
* Returns the number of destinations available for the current {@link Extractor}.
|
|
71
77
|
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
@@ -193,9 +199,12 @@ declare type Standard<T> = ParentProps<{
|
|
|
193
199
|
declare class State {
|
|
194
200
|
#private;
|
|
195
201
|
get sources(): OrderedLinkedList<Info>;
|
|
202
|
+
get sourceCount(): number;
|
|
196
203
|
get destCount(): number;
|
|
197
|
-
shift(k: number): void;
|
|
198
204
|
force(): void;
|
|
205
|
+
shiftSource(k: number): void;
|
|
206
|
+
shiftDest(k: number): void;
|
|
207
|
+
shiftSourceAndForce(k: number): void;
|
|
199
208
|
}
|
|
200
209
|
|
|
201
210
|
/** Type of an element wrapping call-back which accepts an additional parameter */
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { untrack, createRoot, getOwner, createMemo, Show, createContext, useContext, onCleanup, For, createRenderEffect, on, splitProps, createSignal, createSelector, equalFn, Match, runWithOwner } from "solid-js";
|
|
1
|
+
import { untrack, createRoot, getOwner, createMemo, Show, createContext, useContext, onCleanup, For, createRenderEffect, on, splitProps, createSignal, batch, createSelector, equalFn, Match, runWithOwner } from "solid-js";
|
|
2
2
|
import { createComponent, memo, mergeProps, spread } from "solid-js/web";
|
|
3
3
|
function untrackCall(f, ...args) {
|
|
4
4
|
return untrack(() => f.apply(this, args));
|
|
@@ -85,24 +85,37 @@ const COMPARATOR = (a, b) => (a.order ?? 0) - (b.order ?? 0);
|
|
|
85
85
|
const SOURCES_OPTS = {
|
|
86
86
|
internal: true,
|
|
87
87
|
equals: false
|
|
88
|
-
},
|
|
88
|
+
}, COUNT_OPTS = {
|
|
89
89
|
internal: true
|
|
90
90
|
};
|
|
91
91
|
class State {
|
|
92
92
|
#sources = createSignal(new OrderedLinkedList(), SOURCES_OPTS);
|
|
93
|
-
#
|
|
93
|
+
#sourceCount = createSignal(0, COUNT_OPTS);
|
|
94
|
+
#destCount = createSignal(0, COUNT_OPTS);
|
|
94
95
|
get sources() {
|
|
95
96
|
return this.#sources[0]();
|
|
96
97
|
}
|
|
98
|
+
get sourceCount() {
|
|
99
|
+
return this.#sourceCount[0]();
|
|
100
|
+
}
|
|
97
101
|
get destCount() {
|
|
98
102
|
return this.#destCount[0]();
|
|
99
103
|
}
|
|
100
|
-
shift(k) {
|
|
101
|
-
this.#destCount[1]((v) => v + k);
|
|
102
|
-
}
|
|
103
104
|
force() {
|
|
104
105
|
this.#sources[1]((v) => v);
|
|
105
106
|
}
|
|
107
|
+
shiftSource(k) {
|
|
108
|
+
this.#sourceCount[1]((v) => v + k);
|
|
109
|
+
}
|
|
110
|
+
shiftDest(k) {
|
|
111
|
+
this.#destCount[1]((v) => v + k);
|
|
112
|
+
}
|
|
113
|
+
shiftSourceAndForce(k) {
|
|
114
|
+
batch(() => {
|
|
115
|
+
this.shiftSource(k);
|
|
116
|
+
this.force();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
106
119
|
}
|
|
107
120
|
class Extractor {
|
|
108
121
|
constructor(name) {
|
|
@@ -115,6 +128,15 @@ class Extractor {
|
|
|
115
128
|
Dest = Dest.bind(this);
|
|
116
129
|
Source = Source.bind(this);
|
|
117
130
|
SameContextSource = SameContextSource.bind(this);
|
|
131
|
+
/**
|
|
132
|
+
* Returns the number of sources available for the current {@link Extractor}.
|
|
133
|
+
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
134
|
+
* If the current {@link Owner} is NOT under a {@link Joint}, it will return `undefined`
|
|
135
|
+
*/
|
|
136
|
+
get getSourceCount() {
|
|
137
|
+
const state = useContext(this.ctx);
|
|
138
|
+
return state && (() => state.sourceCount);
|
|
139
|
+
}
|
|
118
140
|
/**
|
|
119
141
|
* Returns the number of destinations available for the current {@link Extractor}.
|
|
120
142
|
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
@@ -138,8 +160,8 @@ function Dest(props) {
|
|
|
138
160
|
const state = useContext(this.ctx);
|
|
139
161
|
if (!state)
|
|
140
162
|
return memo(() => props.children);
|
|
141
|
-
onCleanup(() => state.
|
|
142
|
-
state.
|
|
163
|
+
onCleanup(() => state.shiftDest(-1));
|
|
164
|
+
state.shiftDest(1);
|
|
143
165
|
return createComponent(For, {
|
|
144
166
|
get each() {
|
|
145
167
|
return [...state.sources];
|
|
@@ -170,10 +192,10 @@ function Source(props) {
|
|
|
170
192
|
createRenderEffect(on(order, () => {
|
|
171
193
|
onCleanup(() => {
|
|
172
194
|
node.remove();
|
|
173
|
-
state.
|
|
195
|
+
state.shiftSourceAndForce(-1);
|
|
174
196
|
});
|
|
175
197
|
sources.add(node, COMPARATOR);
|
|
176
|
-
state.
|
|
198
|
+
state.shiftSourceAndForce(1);
|
|
177
199
|
}));
|
|
178
200
|
}
|
|
179
201
|
function SameContextSource(props) {
|
package/dist/index.umd.js
CHANGED
|
@@ -87,24 +87,37 @@
|
|
|
87
87
|
const SOURCES_OPTS = {
|
|
88
88
|
internal: true,
|
|
89
89
|
equals: false
|
|
90
|
-
},
|
|
90
|
+
}, COUNT_OPTS = {
|
|
91
91
|
internal: true
|
|
92
92
|
};
|
|
93
93
|
class State {
|
|
94
94
|
#sources = solidJs.createSignal(new OrderedLinkedList(), SOURCES_OPTS);
|
|
95
|
-
#
|
|
95
|
+
#sourceCount = solidJs.createSignal(0, COUNT_OPTS);
|
|
96
|
+
#destCount = solidJs.createSignal(0, COUNT_OPTS);
|
|
96
97
|
get sources() {
|
|
97
98
|
return this.#sources[0]();
|
|
98
99
|
}
|
|
100
|
+
get sourceCount() {
|
|
101
|
+
return this.#sourceCount[0]();
|
|
102
|
+
}
|
|
99
103
|
get destCount() {
|
|
100
104
|
return this.#destCount[0]();
|
|
101
105
|
}
|
|
102
|
-
shift(k) {
|
|
103
|
-
this.#destCount[1]((v) => v + k);
|
|
104
|
-
}
|
|
105
106
|
force() {
|
|
106
107
|
this.#sources[1]((v) => v);
|
|
107
108
|
}
|
|
109
|
+
shiftSource(k) {
|
|
110
|
+
this.#sourceCount[1]((v) => v + k);
|
|
111
|
+
}
|
|
112
|
+
shiftDest(k) {
|
|
113
|
+
this.#destCount[1]((v) => v + k);
|
|
114
|
+
}
|
|
115
|
+
shiftSourceAndForce(k) {
|
|
116
|
+
solidJs.batch(() => {
|
|
117
|
+
this.shiftSource(k);
|
|
118
|
+
this.force();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
108
121
|
}
|
|
109
122
|
class Extractor {
|
|
110
123
|
constructor(name) {
|
|
@@ -117,6 +130,15 @@
|
|
|
117
130
|
Dest = Dest.bind(this);
|
|
118
131
|
Source = Source.bind(this);
|
|
119
132
|
SameContextSource = SameContextSource.bind(this);
|
|
133
|
+
/**
|
|
134
|
+
* Returns the number of sources available for the current {@link Extractor}.
|
|
135
|
+
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
136
|
+
* If the current {@link Owner} is NOT under a {@link Joint}, it will return `undefined`
|
|
137
|
+
*/
|
|
138
|
+
get getSourceCount() {
|
|
139
|
+
const state = solidJs.useContext(this.ctx);
|
|
140
|
+
return state && (() => state.sourceCount);
|
|
141
|
+
}
|
|
120
142
|
/**
|
|
121
143
|
* Returns the number of destinations available for the current {@link Extractor}.
|
|
122
144
|
* It's a getter that returns a function that will be bound to the {@link Owner} in which the getter was called.
|
|
@@ -140,8 +162,8 @@
|
|
|
140
162
|
const state = solidJs.useContext(this.ctx);
|
|
141
163
|
if (!state)
|
|
142
164
|
return web.memo(() => props.children);
|
|
143
|
-
solidJs.onCleanup(() => state.
|
|
144
|
-
state.
|
|
165
|
+
solidJs.onCleanup(() => state.shiftDest(-1));
|
|
166
|
+
state.shiftDest(1);
|
|
145
167
|
return web.createComponent(solidJs.For, {
|
|
146
168
|
get each() {
|
|
147
169
|
return [...state.sources];
|
|
@@ -172,10 +194,10 @@
|
|
|
172
194
|
solidJs.createRenderEffect(solidJs.on(order, () => {
|
|
173
195
|
solidJs.onCleanup(() => {
|
|
174
196
|
node.remove();
|
|
175
|
-
state.
|
|
197
|
+
state.shiftSourceAndForce(-1);
|
|
176
198
|
});
|
|
177
199
|
sources.add(node, COMPARATOR);
|
|
178
|
-
state.
|
|
200
|
+
state.shiftSourceAndForce(1);
|
|
179
201
|
}));
|
|
180
202
|
}
|
|
181
203
|
function SameContextSource(props) {
|
package/package.json
CHANGED
package/readMe.md
CHANGED
|
@@ -196,6 +196,8 @@ return <>
|
|
|
196
196
|
</e.Joint>
|
|
197
197
|
</>
|
|
198
198
|
```
|
|
199
|
+
> Same applies to `Extractor.getSourceCount()`
|
|
200
|
+
|
|
199
201
|
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
202
|
```tsx
|
|
201
203
|
const e = new Extractor(), ctx = createContext(1);
|