solid-ctrl-flow 1.0.9 → 1.0.10
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 +18 -3
- package/dist/index.mjs +36 -12
- package/dist/index.umd.js +35 -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
|
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 } 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,32 @@ 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
|
+
}
|
|
114
137
|
export {
|
|
115
138
|
Case,
|
|
116
139
|
Debug,
|
|
117
140
|
When,
|
|
118
141
|
createExtractor,
|
|
119
142
|
memoProps,
|
|
143
|
+
runWithContext,
|
|
120
144
|
splitAndMemoProps
|
|
121
145
|
};
|
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,32 @@
|
|
|
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
|
+
}
|
|
116
139
|
exports2.Case = Case;
|
|
117
140
|
exports2.Debug = Debug;
|
|
118
141
|
exports2.When = When;
|
|
119
142
|
exports2.createExtractor = createExtractor;
|
|
120
143
|
exports2.memoProps = memoProps;
|
|
144
|
+
exports2.runWithContext = runWithContext;
|
|
121
145
|
exports2.splitAndMemoProps = splitAndMemoProps;
|
|
122
146
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
123
147
|
});
|
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
|