solid-ctrl-flow 1.0.61 → 1.0.63

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 CHANGED
@@ -5,9 +5,6 @@ import { MemoOptions } from 'solid-js';
5
5
  import { Owner } from 'solid-js';
6
6
  import { ParentProps } from 'solid-js';
7
7
 
8
- /** Type hack for making {@link ReactiveContext} implement {@link Accessor} */
9
- declare const BASE_CTOR: new <T>() => Accessor<T>;
10
-
11
8
  /** Like a {@link Match} but gets the value from the closest {@link On} ancestor */
12
9
  export declare function Case(props: ParentProps<{
13
10
  value: unknown;
@@ -73,9 +70,6 @@ export declare function createExtractor(name?: string): {
73
70
  readonly extracting: () => number | null;
74
71
  };
75
72
 
76
- /** Built-in {@link ReactiveContext} which allows you to display different things in debug mode */
77
- export declare const debug: ReactiveContext<boolean>;
78
-
79
73
  /**
80
74
  * Eventually wraps its content into a template if a certain condition is met.
81
75
  * If you set {@link Standard.recycled} to `true`, the content will be memoized in the beginning and will be recycled even if the wrapper changes.
@@ -99,7 +93,7 @@ declare type Keyed<T> = Standard<T> & {
99
93
 
100
94
  /**
101
95
  * Memoizes some of the properties of {@link obj}.
102
- * If {@link keys} is not provided, memoizes everything that get returned by {@link Object.keys} when provided with {@link obj}.
96
+ * If {@link keys} is not provided, memoizes everything that get returned by {@link Reflect.ownKeys} when provided with {@link obj}.
103
97
  * The {@link equals} parameter defaults to `false` to allow the specific reactive value to have control over when its dependant effects are triggered
104
98
  * @param obj Object to partially memoize
105
99
  * @param keys The keys of the properties to memoize
@@ -143,43 +137,6 @@ export declare const On: (props: ParentProps<{
143
137
  value: any;
144
138
  }>) => JSX.Element;
145
139
 
146
- /**
147
- * Reactive {@link Context} with some additional built-in functionalities.
148
- * The call signature returns the value in the current {@link Owner} (It's like calling {@link get})
149
- */
150
- export declare abstract class ReactiveContext<T> extends BASE_CTOR<T> {
151
- /** The actual {@link Context} that contains the reactive {@link Accessor} to the value */
152
- abstract ctx: Context<Accessor<T>>;
153
- /**
154
- * Returns the {@link Accessor} for the value in the current {@link Owner}.
155
- * It's like calling {@link useContext}
156
- */
157
- get get(): Accessor<T>;
158
- /**
159
- * Component that sets the value of the current {@link Context} for its children.
160
- * If no value is provided then it will use the default value for {@link ctx}.
161
- * The function is bound for the way solid compiles components inside other objects.
162
- * (The value is memoized)
163
- */
164
- get Provider(): (props: ParentProps<{
165
- value?: T;
166
- }>) => JSX.Element;
167
- /**
168
- * Executes {@link runWithContext} on the current context
169
- * @param value The value for the context
170
- * @param f The function to run
171
- * @returns The same thing {@link f} returned
172
- */
173
- runWith<V extends T, R>(value: V | undefined, f: (x: V) => R): R;
174
- /**
175
- * Creates a {@link ReactiveContext}
176
- * @param defaultValue Initial value for the context
177
- * @param name Name to give to the context
178
- */
179
- static create<T>(defaultValue?: undefined, name?: string): ReactiveContext<T | undefined>;
180
- static create<T>(defaultValue: T, name?: string): ReactiveContext<T>;
181
- }
182
-
183
140
  /**
184
141
  * Executes {@link f} with the provided value for the specified {@link Context}.
185
142
  * You can pass `undefined` to {@link value} in order to get back the default value for {@link ctx}.
package/dist/index.mjs CHANGED
@@ -1,58 +1,18 @@
1
- import { useContext, createMemo, createComponent, createContext, createRoot, getOwner, untrack, splitProps, Show, onCleanup, For, Match, mergeProps } from "solid-js";
1
+ import { createMemo, splitProps, untrack, createRoot, getOwner, createComponent, Show, createContext, useContext, onCleanup, For, Match, mergeProps } from "solid-js";
2
2
  import { createMutable } from "solid-js/store";
3
- const BASE_CTOR = Function;
4
- class ReactiveContext extends BASE_CTOR {
5
- /** The actual {@link Context} that contains the reactive {@link Accessor} to the value */
6
- /**
7
- * Returns the {@link Accessor} for the value in the current {@link Owner}.
8
- * It's like calling {@link useContext}
9
- */
10
- get get() {
11
- return useContext(this.ctx);
12
- }
13
- /**
14
- * Component that sets the value of the current {@link Context} for its children.
15
- * If no value is provided then it will use the default value for {@link ctx}.
16
- * The function is bound for the way solid compiles components inside other objects.
17
- * (The value is memoized)
18
- */
19
- get Provider() {
20
- const {
21
- ctx: ctx2
22
- } = this;
23
- return function(props) {
24
- const memo = createMemo(() => props.value);
25
- return createComponent(ctx2.Provider, {
26
- value: memo,
27
- get children() {
28
- return props.children;
29
- }
30
- });
31
- };
32
- }
33
- /**
34
- * Executes {@link runWithContext} on the current context
35
- * @param value The value for the context
36
- * @param f The function to run
37
- * @returns The same thing {@link f} returned
38
- */
39
- runWith(value, f) {
40
- return runWithContext(this.ctx, value === void 0 ? void 0 : () => value, (x) => f(x()));
41
- }
42
- /**
43
- * Creates a {@link ReactiveContext}
44
- * @param defaultValue Initial value for the context
45
- * @param name Name to give to the context
46
- */
47
- static create(defaultValue, name) {
48
- const ctx2 = createContext(() => defaultValue, {
49
- name
50
- });
51
- const f = () => out.get();
52
- f.ctx = ctx2;
53
- const out = Object.setPrototypeOf(f, ReactiveContext.prototype);
54
- return out;
55
- }
3
+ function memoProps(obj, keys = Reflect.ownKeys(obj), equals = false) {
4
+ const out = {};
5
+ for (const elm of keys)
6
+ Object.defineProperty(out, elm, { enumerable: true, get: createMemo(() => obj[elm], void 0, { equals }) });
7
+ return out;
8
+ }
9
+ function splitAndMemoProps(obj, keys, equals) {
10
+ const out = splitProps(obj, keys);
11
+ out[0] = memoProps(out[0], keys, equals);
12
+ return out;
13
+ }
14
+ function untrackCall(f, ...args) {
15
+ return untrack(() => f.apply(this, args));
56
16
  }
57
17
  function runWithContext(ctx2, value, f) {
58
18
  return createRoot((d) => {
@@ -64,20 +24,6 @@ function runWithContext(ctx2, value, f) {
64
24
  }
65
25
  });
66
26
  }
67
- function untrackCall(f, ...args) {
68
- return untrack(() => f.apply(this, args));
69
- }
70
- function memoProps(obj, keys = Object.keys(obj), equals = false) {
71
- const out = {};
72
- for (const elm of keys)
73
- Object.defineProperty(out, elm, { enumerable: true, get: createMemo(() => obj[elm], void 0, { equals }) });
74
- return out;
75
- }
76
- function splitAndMemoProps(obj, keys, equals) {
77
- const out = splitProps(obj, keys);
78
- out[0] = memoProps(out[0], keys, equals);
79
- return out;
80
- }
81
27
  const unwrap = (f) => new Proxy(f, HANDLER);
82
28
  const HANDLER = new Proxy({}, {
83
29
  get(cache, k) {
@@ -210,13 +156,18 @@ function createInfo(props) {
210
156
  }
211
157
  };
212
158
  }
213
- const ctx = ReactiveContext.create(void 0, "on-case");
214
- const On = ctx.Provider;
159
+ const ctx = createContext(void 0, {
160
+ name: "on-case"
161
+ });
162
+ const On = (props) => createComponent(ctx.Provider, {
163
+ value: () => props.value,
164
+ get children() {
165
+ return props.children;
166
+ }
167
+ });
215
168
  function Case(props) {
216
169
  const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
217
- const {
218
- get
219
- } = ctx;
170
+ const get = useContext(ctx);
220
171
  const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
221
172
  return createComponent(Match, mergeProps({
222
173
  get when() {
@@ -224,7 +175,6 @@ function Case(props) {
224
175
  }
225
176
  }, other));
226
177
  }
227
- const debug = ReactiveContext.create(false, "debug-scope");
228
178
  function SameContext(props) {
229
179
  return createMemo(() => {
230
180
  getOwner().context = props.owner.context;
@@ -235,11 +185,9 @@ export {
235
185
  Case,
236
186
  Enfold,
237
187
  On,
238
- ReactiveContext,
239
188
  SameContext,
240
189
  Slot,
241
190
  createExtractor,
242
- debug,
243
191
  memoProps,
244
192
  runWithContext,
245
193
  splitAndMemoProps,
package/dist/index.umd.js CHANGED
@@ -2,59 +2,19 @@
2
2
  typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("solid-js"), require("solid-js/store")) : typeof define === "function" && define.amd ? define(["exports", "solid-js", "solid-js/store"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.solidCtrlFlow = {}, global.solidJs, global.solidJsStore));
3
3
  })(this, function(exports2, solidJs, store) {
4
4
  "use strict";
5
- const BASE_CTOR = Function;
6
- class ReactiveContext extends BASE_CTOR {
7
- /** The actual {@link Context} that contains the reactive {@link Accessor} to the value */
8
- /**
9
- * Returns the {@link Accessor} for the value in the current {@link Owner}.
10
- * It's like calling {@link useContext}
11
- */
12
- get get() {
13
- return solidJs.useContext(this.ctx);
14
- }
15
- /**
16
- * Component that sets the value of the current {@link Context} for its children.
17
- * If no value is provided then it will use the default value for {@link ctx}.
18
- * The function is bound for the way solid compiles components inside other objects.
19
- * (The value is memoized)
20
- */
21
- get Provider() {
22
- const {
23
- ctx: ctx2
24
- } = this;
25
- return function(props) {
26
- const memo = solidJs.createMemo(() => props.value);
27
- return solidJs.createComponent(ctx2.Provider, {
28
- value: memo,
29
- get children() {
30
- return props.children;
31
- }
32
- });
33
- };
34
- }
35
- /**
36
- * Executes {@link runWithContext} on the current context
37
- * @param value The value for the context
38
- * @param f The function to run
39
- * @returns The same thing {@link f} returned
40
- */
41
- runWith(value, f) {
42
- return runWithContext(this.ctx, value === void 0 ? void 0 : () => value, (x) => f(x()));
43
- }
44
- /**
45
- * Creates a {@link ReactiveContext}
46
- * @param defaultValue Initial value for the context
47
- * @param name Name to give to the context
48
- */
49
- static create(defaultValue, name) {
50
- const ctx2 = solidJs.createContext(() => defaultValue, {
51
- name
52
- });
53
- const f = () => out.get();
54
- f.ctx = ctx2;
55
- const out = Object.setPrototypeOf(f, ReactiveContext.prototype);
56
- return out;
57
- }
5
+ function memoProps(obj, keys = Reflect.ownKeys(obj), equals = false) {
6
+ const out = {};
7
+ for (const elm of keys)
8
+ Object.defineProperty(out, elm, { enumerable: true, get: solidJs.createMemo(() => obj[elm], void 0, { equals }) });
9
+ return out;
10
+ }
11
+ function splitAndMemoProps(obj, keys, equals) {
12
+ const out = solidJs.splitProps(obj, keys);
13
+ out[0] = memoProps(out[0], keys, equals);
14
+ return out;
15
+ }
16
+ function untrackCall(f, ...args) {
17
+ return solidJs.untrack(() => f.apply(this, args));
58
18
  }
59
19
  function runWithContext(ctx2, value, f) {
60
20
  return solidJs.createRoot((d) => {
@@ -66,20 +26,6 @@
66
26
  }
67
27
  });
68
28
  }
69
- function untrackCall(f, ...args) {
70
- return solidJs.untrack(() => f.apply(this, args));
71
- }
72
- function memoProps(obj, keys = Object.keys(obj), equals = false) {
73
- const out = {};
74
- for (const elm of keys)
75
- Object.defineProperty(out, elm, { enumerable: true, get: solidJs.createMemo(() => obj[elm], void 0, { equals }) });
76
- return out;
77
- }
78
- function splitAndMemoProps(obj, keys, equals) {
79
- const out = solidJs.splitProps(obj, keys);
80
- out[0] = memoProps(out[0], keys, equals);
81
- return out;
82
- }
83
29
  const unwrap = (f) => new Proxy(f, HANDLER);
84
30
  const HANDLER = new Proxy({}, {
85
31
  get(cache, k) {
@@ -212,13 +158,18 @@
212
158
  }
213
159
  };
214
160
  }
215
- const ctx = ReactiveContext.create(void 0, "on-case");
216
- const On = ctx.Provider;
161
+ const ctx = solidJs.createContext(void 0, {
162
+ name: "on-case"
163
+ });
164
+ const On = (props) => solidJs.createComponent(ctx.Provider, {
165
+ value: () => props.value,
166
+ get children() {
167
+ return props.children;
168
+ }
169
+ });
217
170
  function Case(props) {
218
171
  const [mine, other] = splitAndMemoProps(props, ["value", "pred"]);
219
- const {
220
- get
221
- } = ctx;
172
+ const get = solidJs.useContext(ctx);
222
173
  const pred = (x) => mine.pred ? mine.pred(x) : x === mine.value;
223
174
  return solidJs.createComponent(solidJs.Match, solidJs.mergeProps({
224
175
  get when() {
@@ -226,7 +177,6 @@
226
177
  }
227
178
  }, other));
228
179
  }
229
- const debug = ReactiveContext.create(false, "debug-scope");
230
180
  function SameContext(props) {
231
181
  return solidJs.createMemo(() => {
232
182
  solidJs.getOwner().context = props.owner.context;
@@ -236,10 +186,8 @@
236
186
  exports2.Case = Case;
237
187
  exports2.Enfold = Enfold;
238
188
  exports2.On = On;
239
- exports2.ReactiveContext = ReactiveContext;
240
189
  exports2.SameContext = SameContext;
241
190
  exports2.createExtractor = createExtractor;
242
- exports2.debug = debug;
243
191
  exports2.memoProps = memoProps;
244
192
  exports2.runWithContext = runWithContext;
245
193
  exports2.splitAndMemoProps = splitAndMemoProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.61",
3
+ "version": "1.0.63",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
package/readMe.md CHANGED
@@ -162,40 +162,17 @@ return <>
162
162
 
163
163
  ## Utility
164
164
 
165
- ### `ReactiveContext.create()`
166
- Method that creates a reactive version of a solid `Context` with some additional built-in functionalities
167
- ```ts
168
- const ctx = ReactiveContext.create("SOMETHING");
169
- const underlyingNormalContext = ctx.ctx;
170
- const valueAccessorForTheCurrentOwner = ctx.get;
171
- const value = ctx();
172
- ```
173
-
174
- ### `runWithContext()`
175
- Creates a context scope that persists for the duration of a function
176
-
177
165
  ### `unwrap()`
178
166
  Calls an `Accessor` maintaining its reactivity at 1 level
179
167
 
180
- ### `debug()`
181
- Allows you to define ui section that are only visible in debug or NOT in debug
182
- ```tsx
183
- const value = false;
184
- return <>
185
- <debug.Provider value={value}>
186
- {/* (A LOT OF NESTING...) */}
187
- <Show when={debug()}>
188
- THIS WOULD BE VISIBLE IF "value" HAD BEEN {true}
189
- </Show>
190
- </debug.Provider>
191
- </>
192
- ```
193
-
194
- ### `untrackCall()`
195
- Calls a function untracking what happens inside of it but not what gets passed as its argument
196
-
197
168
  ### `memoProps()`
198
169
  Creates a partial version of an object with memoized remaining properties
199
170
 
200
171
  ### `splitAndMemoProps()`
201
- Like `splitProps()` but memoizes the whole local part
172
+ Like `splitProps()` but memoizes the whole local part
173
+
174
+ ### `untrackCall()`
175
+ Calls a function untracking what happens inside of it but not what gets passed as its argument
176
+
177
+ ### `runWithContext()`
178
+ Creates a context scope that persists for the duration of a function