solid-ctrl-flow 1.0.9 → 1.0.11
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 +28 -3
- package/dist/index.mjs +41 -13
- package/dist/index.umd.js +39 -11
- package/package.json +1 -1
- package/{readme.md → readMe.md} +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Accessor } from 'solid-js';
|
|
2
|
+
import { Context } from 'solid-js';
|
|
2
3
|
import { JSX } from 'solid-js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -61,9 +62,7 @@ export declare function createExtractor(name?: string): {
|
|
|
61
62
|
/** Bound {@link Dest} */
|
|
62
63
|
Dest: () => JSX.Element;
|
|
63
64
|
/** Bound {@link Source} */
|
|
64
|
-
Source: (props:
|
|
65
|
-
children: JSX.Element;
|
|
66
|
-
}) => JSX.Element;
|
|
65
|
+
Source: (props: Info) => JSX.Element;
|
|
67
66
|
/** Bound {@link Joint} */
|
|
68
67
|
Joint: (props: {
|
|
69
68
|
children: JSX.Element;
|
|
@@ -87,6 +86,13 @@ export declare namespace Debug {
|
|
|
87
86
|
const isDebug: Accessor<boolean>;
|
|
88
87
|
}
|
|
89
88
|
|
|
89
|
+
/** Informations about a {@link Source} component */
|
|
90
|
+
declare type Info = {
|
|
91
|
+
/** Order of the current source if there are many */
|
|
92
|
+
order?: number;
|
|
93
|
+
children: JSX.Element;
|
|
94
|
+
};
|
|
95
|
+
|
|
90
96
|
/**
|
|
91
97
|
* Memoizes some of the properties of {@link obj}
|
|
92
98
|
* If {@link keys} is not provided, memoizes everything that get returned by {@link Object.keys} when provided with {@link obj}
|
|
@@ -95,6 +101,15 @@ export declare namespace Debug {
|
|
|
95
101
|
*/
|
|
96
102
|
export declare function memoProps<T, K extends readonly (keyof T)[] = (keyof T)[]>(obj: T, keys?: K): Pick<T, K[number]>;
|
|
97
103
|
|
|
104
|
+
/**
|
|
105
|
+
* Executes {@link f} with the provided {@link Context}
|
|
106
|
+
* @param ctx The context to which to set the value
|
|
107
|
+
* @param value The value for the context
|
|
108
|
+
* @param f The function to run
|
|
109
|
+
* @returns The same thing {@link f} returned
|
|
110
|
+
*/
|
|
111
|
+
export declare function runWithContext<T, R>(ctx: Context<T>, value: T, f: (x: T) => R): Promise<R>;
|
|
112
|
+
|
|
98
113
|
/**
|
|
99
114
|
* Esecutes {@link splitProps} and memoizes the first of the two returned objects
|
|
100
115
|
* @param obj Object to split and partially memoize
|
|
@@ -102,6 +117,16 @@ export declare function memoProps<T, K extends readonly (keyof T)[] = (keyof T)[
|
|
|
102
117
|
*/
|
|
103
118
|
export declare function splitAndMemoProps<T extends object, K extends readonly (keyof T)[]>(obj: T, keys: K): readonly [Pick<Pick<T, Extract<K, readonly (keyof T)[]>[number]>, K[number]>, Omit<T, K[number]>];
|
|
104
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Executes {@link f} untracking it.
|
|
122
|
+
* Due to the fact that the function is passed as input, it does not untrack its changes (It's intentional)
|
|
123
|
+
* @param this The same thing that {@link f} wants as `this`
|
|
124
|
+
* @param f The function to call
|
|
125
|
+
* @param args Arguments for calling {@link f}
|
|
126
|
+
* @returns The same thing {@link f} returned
|
|
127
|
+
*/
|
|
128
|
+
export declare function untrackCall<F extends (...args: any[]) => any>(this: ThisParameterType<F>, f: F, ...args: Parameters<F>): any;
|
|
129
|
+
|
|
105
130
|
/** Like a {@link Match} but gets the value from the closest {@link Case} ancestor */
|
|
106
131
|
export declare function When(props: {
|
|
107
132
|
value: unknown;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, createMemo, createComponent, useContext, Match, mergeProps, onCleanup, Show, splitProps } from "solid-js";
|
|
1
|
+
import { createContext, createMemo, createComponent, useContext, Match, mergeProps, onCleanup, For, Show, splitProps, createRoot, getOwner, untrack } from "solid-js";
|
|
2
2
|
import { createMutable } from "solid-js/store";
|
|
3
3
|
const ctx$1 = createContext(() => void 0, {
|
|
4
4
|
name: "case-when"
|
|
@@ -65,22 +65,34 @@ function Dest() {
|
|
|
65
65
|
return;
|
|
66
66
|
obj.attached++;
|
|
67
67
|
onCleanup(() => obj.attached--);
|
|
68
|
-
return
|
|
68
|
+
return createComponent(For, {
|
|
69
|
+
get each() {
|
|
70
|
+
return obj.source.sort((a, b) => a.order - b.order);
|
|
71
|
+
},
|
|
72
|
+
children: (x) => createMemo(() => x.children)
|
|
73
|
+
});
|
|
69
74
|
}
|
|
70
75
|
function Source(props) {
|
|
71
76
|
const obj = useContext(this);
|
|
72
77
|
if (!obj)
|
|
73
78
|
return props.children;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
const order = createMemo(() => props.order || 0);
|
|
80
|
+
const info = {
|
|
81
|
+
get order() {
|
|
82
|
+
return order();
|
|
83
|
+
},
|
|
84
|
+
get children() {
|
|
85
|
+
return props.children;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
obj.source.push(info);
|
|
89
|
+
onCleanup(() => obj.source.splice(obj.source.indexOf(info), 1));
|
|
78
90
|
return createComponent(Show, {
|
|
79
91
|
get when() {
|
|
80
92
|
return !obj.attached;
|
|
81
93
|
},
|
|
82
94
|
get children() {
|
|
83
|
-
return
|
|
95
|
+
return info.children;
|
|
84
96
|
}
|
|
85
97
|
});
|
|
86
98
|
}
|
|
@@ -89,7 +101,8 @@ function Joint(props) {
|
|
|
89
101
|
Provider
|
|
90
102
|
} = this;
|
|
91
103
|
const obj = createMutable({
|
|
92
|
-
attached: 0
|
|
104
|
+
attached: 0,
|
|
105
|
+
source: []
|
|
93
106
|
});
|
|
94
107
|
return createComponent(Provider, {
|
|
95
108
|
value: obj,
|
|
@@ -101,21 +114,36 @@ function Joint(props) {
|
|
|
101
114
|
function memoProps(obj, keys = Object.keys(obj)) {
|
|
102
115
|
const out = {};
|
|
103
116
|
for (const elm of keys)
|
|
104
|
-
Object.defineProperty(out, elm, {
|
|
105
|
-
enumerable: true,
|
|
106
|
-
get: createMemo(() => obj[elm])
|
|
107
|
-
});
|
|
117
|
+
Object.defineProperty(out, elm, { enumerable: true, get: createMemo(() => obj[elm]) });
|
|
108
118
|
return out;
|
|
109
119
|
}
|
|
110
120
|
function splitAndMemoProps(obj, keys) {
|
|
111
121
|
const [mine, other] = splitProps(obj, keys);
|
|
112
122
|
return [memoProps(mine, keys), other];
|
|
113
123
|
}
|
|
124
|
+
function runWithContext(ctx2, value, f) {
|
|
125
|
+
return createRoot(async (d) => {
|
|
126
|
+
try {
|
|
127
|
+
getOwner().context = { [ctx2.id]: value };
|
|
128
|
+
const out = f(value);
|
|
129
|
+
if (out instanceof Promise)
|
|
130
|
+
return out.finally(d);
|
|
131
|
+
return d(), out;
|
|
132
|
+
} catch (ex) {
|
|
133
|
+
throw d(), ex;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function untrackCall(f, ...args) {
|
|
138
|
+
return untrack(() => f.apply(this, args));
|
|
139
|
+
}
|
|
114
140
|
export {
|
|
115
141
|
Case,
|
|
116
142
|
Debug,
|
|
117
143
|
When,
|
|
118
144
|
createExtractor,
|
|
119
145
|
memoProps,
|
|
120
|
-
|
|
146
|
+
runWithContext,
|
|
147
|
+
splitAndMemoProps,
|
|
148
|
+
untrackCall
|
|
121
149
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -67,22 +67,34 @@
|
|
|
67
67
|
return;
|
|
68
68
|
obj.attached++;
|
|
69
69
|
solidJs.onCleanup(() => obj.attached--);
|
|
70
|
-
return solidJs.
|
|
70
|
+
return solidJs.createComponent(solidJs.For, {
|
|
71
|
+
get each() {
|
|
72
|
+
return obj.source.sort((a, b) => a.order - b.order);
|
|
73
|
+
},
|
|
74
|
+
children: (x) => solidJs.createMemo(() => x.children)
|
|
75
|
+
});
|
|
71
76
|
}
|
|
72
77
|
function Source(props) {
|
|
73
78
|
const obj = solidJs.useContext(this);
|
|
74
79
|
if (!obj)
|
|
75
80
|
return props.children;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
const order = solidJs.createMemo(() => props.order || 0);
|
|
82
|
+
const info = {
|
|
83
|
+
get order() {
|
|
84
|
+
return order();
|
|
85
|
+
},
|
|
86
|
+
get children() {
|
|
87
|
+
return props.children;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
obj.source.push(info);
|
|
91
|
+
solidJs.onCleanup(() => obj.source.splice(obj.source.indexOf(info), 1));
|
|
80
92
|
return solidJs.createComponent(solidJs.Show, {
|
|
81
93
|
get when() {
|
|
82
94
|
return !obj.attached;
|
|
83
95
|
},
|
|
84
96
|
get children() {
|
|
85
|
-
return
|
|
97
|
+
return info.children;
|
|
86
98
|
}
|
|
87
99
|
});
|
|
88
100
|
}
|
|
@@ -91,7 +103,8 @@
|
|
|
91
103
|
Provider
|
|
92
104
|
} = this;
|
|
93
105
|
const obj = store.createMutable({
|
|
94
|
-
attached: 0
|
|
106
|
+
attached: 0,
|
|
107
|
+
source: []
|
|
95
108
|
});
|
|
96
109
|
return solidJs.createComponent(Provider, {
|
|
97
110
|
value: obj,
|
|
@@ -103,21 +116,36 @@
|
|
|
103
116
|
function memoProps(obj, keys = Object.keys(obj)) {
|
|
104
117
|
const out = {};
|
|
105
118
|
for (const elm of keys)
|
|
106
|
-
Object.defineProperty(out, elm, {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
get: solidJs.createMemo(() => obj[elm])
|
|
109
|
-
});
|
|
119
|
+
Object.defineProperty(out, elm, { enumerable: true, get: solidJs.createMemo(() => obj[elm]) });
|
|
110
120
|
return out;
|
|
111
121
|
}
|
|
112
122
|
function splitAndMemoProps(obj, keys) {
|
|
113
123
|
const [mine, other] = solidJs.splitProps(obj, keys);
|
|
114
124
|
return [memoProps(mine, keys), other];
|
|
115
125
|
}
|
|
126
|
+
function runWithContext(ctx2, value, f) {
|
|
127
|
+
return solidJs.createRoot(async (d) => {
|
|
128
|
+
try {
|
|
129
|
+
solidJs.getOwner().context = { [ctx2.id]: value };
|
|
130
|
+
const out = f(value);
|
|
131
|
+
if (out instanceof Promise)
|
|
132
|
+
return out.finally(d);
|
|
133
|
+
return d(), out;
|
|
134
|
+
} catch (ex) {
|
|
135
|
+
throw d(), ex;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function untrackCall(f, ...args) {
|
|
140
|
+
return solidJs.untrack(() => f.apply(this, args));
|
|
141
|
+
}
|
|
116
142
|
exports2.Case = Case;
|
|
117
143
|
exports2.Debug = Debug;
|
|
118
144
|
exports2.When = When;
|
|
119
145
|
exports2.createExtractor = createExtractor;
|
|
120
146
|
exports2.memoProps = memoProps;
|
|
147
|
+
exports2.runWithContext = runWithContext;
|
|
121
148
|
exports2.splitAndMemoProps = splitAndMemoProps;
|
|
149
|
+
exports2.untrackCall = untrackCall;
|
|
122
150
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
123
151
|
});
|
package/package.json
CHANGED
package/{readme.md → readMe.md}
RENAMED
|
@@ -120,4 +120,7 @@ Utility functions needed for the components above
|
|
|
120
120
|
Creates a partial version of an object with memoized remaining properties
|
|
121
121
|
|
|
122
122
|
### `splitAndMemoProps()`
|
|
123
|
-
Like `splitProps()` but memoizes the whole local part
|
|
123
|
+
Like `splitProps()` but memoizes the whole local part
|
|
124
|
+
|
|
125
|
+
### `runWithContext()`
|
|
126
|
+
Creates a context scope that persists for the duration of a function
|