solid-ctrl-flow 1.0.40 → 1.0.42

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
@@ -19,11 +19,12 @@ declare const BASE_CTOR: new <T>() => Accessor<T>;
19
19
  * @param source The getter of the source of the binding
20
20
  * @param dest The setter of the destination of the binding
21
21
  * @param to Conversion function from {@link S} to {@link D}
22
+ * @param skip If it is `true`, {@link dest} won't be executed until the next change
22
23
  * @returns A function that disposes the binding
23
24
  */
24
- export declare function bind<S>(source: Accessor<S>, dest: Setter<S>): () => void;
25
+ export declare function bind<S>(source: Accessor<S>, dest: Setter<S>, to?: undefined, skip?: boolean): () => void;
25
26
 
26
- export declare function bind<S, D>(source: Accessor<S>, dest: Setter<D>, to: Convert<S, D>): () => void;
27
+ export declare function bind<S, D>(source: Accessor<S>, dest: Setter<D>, to: Convert<S, D>, skip?: boolean): () => void;
27
28
 
28
29
  /**
29
30
  * Creates a two-way binding between two {@link Signal}s calling {@link bind} two times
@@ -148,7 +149,7 @@ export declare function Enfold<T>(props: Unkeyed<T>): JSX.Element;
148
149
  declare type Equals = MemoOptions<unknown>["equals"];
149
150
 
150
151
  /** Informations about a {@link Source} component */
151
- declare type Info = {
152
+ declare type Info = Slot & {
152
153
  /** Order of the current source if there are many */
153
154
  order?: number;
154
155
  children: JSX.Element;
@@ -244,6 +245,36 @@ export declare function runWithContext<T, V extends T, R>(ctx: Context<T>, value
244
245
 
245
246
  export declare function runWithContext<T, R>(ctx: Context<T>, value: T | undefined, f: (x: T) => R): R;
246
247
 
248
+ /** Element which tracks its index in its containing array */
249
+ export declare interface Slot {
250
+ slot?: number;
251
+ }
252
+
253
+ /** Utility of {@link Slot}s */
254
+ export declare namespace Slot {
255
+ /**
256
+ * Pushes an element into a slotted list
257
+ * @param list The list in which to add the element
258
+ * @param v The element to add to {@link list}
259
+ * @returns The index of the new element
260
+ */
261
+ const push: <T extends Slot>(list: T[], v: T) => number;
262
+ /**
263
+ * Exactly like {@link removeSlotAt}, but it gets the index from {@link v}
264
+ * @param list The list from which to remove the element
265
+ * @param v The element to remove from {@link list}
266
+ * @returns The removed element
267
+ */
268
+ const remove: <T extends Slot>(list: T[], v: T) => T | undefined;
269
+ /**
270
+ * Removes an element from a slotted list
271
+ * @param list The list from which to remove the element
272
+ * @param i The index at which to remove the element
273
+ * @returns The removed element
274
+ */
275
+ export function removeAt<T extends Slot>(list: T[], i: number): T | undefined;
276
+ }
277
+
247
278
  /**
248
279
  * Executes {@link splitProps} and memoizes the first of the two returned objects using {@link memoProps}
249
280
  * @param obj Object to split and partially memoize
@@ -293,7 +324,8 @@ declare type Unkeyed<T> = Standard<T> & {
293
324
  export declare function untrackCall<F extends (...args: any[]) => unknown>(this: ThisParameterType<F>, f: F, ...args: Parameters<F>): ReturnType<F>;
294
325
 
295
326
  /**
296
- * Calls an {@link Accessor} maintaining its reactivity at 1 level
327
+ * Calls an {@link Accessor} maintaining its reactivity at 1 level.
328
+ * The `typeof` operator on the output returns `"function"`, so you have to wrap it if you use it in, for example, in a {@link Setter} and you don't want it to be invoked
297
329
  * @param f The {@link Accessor} to the value to emulate
298
330
  * @returns A {@link Proxy} that copies the functionalities of the result of {@link f} calling it for each interaction, thus maintaining reactivity
299
331
  */
package/dist/index.mjs CHANGED
@@ -81,12 +81,7 @@ function When(props) {
81
81
  function memoProps(obj, keys = Object.keys(obj), equals = false) {
82
82
  const out = {};
83
83
  for (const elm of keys)
84
- Object.defineProperty(out, elm, {
85
- enumerable: true,
86
- get: createMemo(() => obj[elm], void 0, {
87
- equals
88
- })
89
- });
84
+ Object.defineProperty(out, elm, { enumerable: true, get: createMemo(() => obj[elm], void 0, { equals }) });
90
85
  return out;
91
86
  }
92
87
  function splitAndMemoProps(obj, keys, equals) {
@@ -98,9 +93,7 @@ function createReactiveResource(f) {
98
93
  var refetch;
99
94
  const memo = createMemo(f);
100
95
  createEffect(on(memo, () => refetch?.()));
101
- const [get] = [, {
102
- refetch
103
- }] = createResource(memo);
96
+ const [get] = [, { refetch }] = createResource(memo);
104
97
  return get;
105
98
  }
106
99
  function untrackCall(f, ...args) {
@@ -130,6 +123,23 @@ function Enfold(props) {
130
123
  children: (x) => createMemo(() => untrackCall(props.template, children, x))
131
124
  });
132
125
  }
126
+ var Slot;
127
+ ((Slot2) => {
128
+ Slot2.push = (list, v) => v.slot = list.push(v) - 1;
129
+ Slot2.remove = (list, v) => v.slot != null ? removeAt(list, v.slot) : v;
130
+ function removeAt(list, i) {
131
+ if (i >= list.length)
132
+ return;
133
+ const last = list.pop();
134
+ if (i === list.length - 1)
135
+ return last;
136
+ const out = list[i];
137
+ out.slot = void 0;
138
+ list[last.slot = i] = last;
139
+ return out;
140
+ }
141
+ Slot2.removeAt = removeAt;
142
+ })(Slot || (Slot = {}));
133
143
  function createExtractor(name = "extractor") {
134
144
  const ctx2 = createContext(void 0, {
135
145
  name
@@ -159,7 +169,7 @@ function Dest() {
159
169
  onCleanup(() => obj.attached--);
160
170
  return createComponent(For, {
161
171
  get each() {
162
- return obj.source.sort((a, b) => a.order - b.order);
172
+ return obj.source.toSorted((a, b) => a.order - b.order);
163
173
  },
164
174
  children: (x) => createMemo(() => x.children)
165
175
  });
@@ -177,8 +187,8 @@ function Source(props) {
177
187
  return props.children;
178
188
  }
179
189
  };
180
- obj.source.push(info);
181
- onCleanup(() => obj.source.splice(obj.source.indexOf(createMutable(info)), 1));
190
+ Slot.push(obj.source, info);
191
+ onCleanup(() => Slot.remove(obj.source, info));
182
192
  return createComponent(Show, {
183
193
  get when() {
184
194
  return !obj.attached;
@@ -217,13 +227,13 @@ function Nest(props) {
217
227
  return createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
218
228
  }
219
229
  const IDENTITY = (x) => x;
220
- function bind(source, dest, to = IDENTITY) {
221
- const d = createRoot((d2) => (createRenderEffect(on(source, (x) => dest((prev) => to(x, prev)))), d2));
230
+ function bind(source, dest, to = IDENTITY, skip = false) {
231
+ const d = createRoot((d2) => (createRenderEffect(on(source, (x) => skip ? skip = false : dest((prev) => to(x, prev)))), d2));
222
232
  return onCleanup(d), d;
223
233
  }
224
234
  function bindTwoWay(source, dest, to, from) {
225
235
  const a = bind(source[0], dest[1], to);
226
- const b = bind(dest[0], source[1], from);
236
+ const b = bind(dest[0], source[1], from, true);
227
237
  return () => (a(), b());
228
238
  }
229
239
  function toSetter(get, set) {
@@ -248,6 +258,7 @@ export {
248
258
  Enfold,
249
259
  Nest,
250
260
  ReactiveContext,
261
+ Slot,
251
262
  When,
252
263
  bind,
253
264
  bindTwoWay,
package/dist/index.umd.js CHANGED
@@ -83,12 +83,7 @@
83
83
  function memoProps(obj, keys = Object.keys(obj), equals = false) {
84
84
  const out = {};
85
85
  for (const elm of keys)
86
- Object.defineProperty(out, elm, {
87
- enumerable: true,
88
- get: solidJs.createMemo(() => obj[elm], void 0, {
89
- equals
90
- })
91
- });
86
+ Object.defineProperty(out, elm, { enumerable: true, get: solidJs.createMemo(() => obj[elm], void 0, { equals }) });
92
87
  return out;
93
88
  }
94
89
  function splitAndMemoProps(obj, keys, equals) {
@@ -100,9 +95,7 @@
100
95
  var refetch;
101
96
  const memo = solidJs.createMemo(f);
102
97
  solidJs.createEffect(solidJs.on(memo, () => refetch?.()));
103
- const [get] = [, {
104
- refetch
105
- }] = solidJs.createResource(memo);
98
+ const [get] = [, { refetch }] = solidJs.createResource(memo);
106
99
  return get;
107
100
  }
108
101
  function untrackCall(f, ...args) {
@@ -132,6 +125,23 @@
132
125
  children: (x) => solidJs.createMemo(() => untrackCall(props.template, children, x))
133
126
  });
134
127
  }
128
+ exports2.Slot = void 0;
129
+ ((Slot2) => {
130
+ Slot2.push = (list, v) => v.slot = list.push(v) - 1;
131
+ Slot2.remove = (list, v) => v.slot != null ? removeAt(list, v.slot) : v;
132
+ function removeAt(list, i) {
133
+ if (i >= list.length)
134
+ return;
135
+ const last = list.pop();
136
+ if (i === list.length - 1)
137
+ return last;
138
+ const out = list[i];
139
+ out.slot = void 0;
140
+ list[last.slot = i] = last;
141
+ return out;
142
+ }
143
+ Slot2.removeAt = removeAt;
144
+ })(exports2.Slot || (exports2.Slot = {}));
135
145
  function createExtractor(name = "extractor") {
136
146
  const ctx2 = solidJs.createContext(void 0, {
137
147
  name
@@ -161,7 +171,7 @@
161
171
  solidJs.onCleanup(() => obj.attached--);
162
172
  return solidJs.createComponent(solidJs.For, {
163
173
  get each() {
164
- return obj.source.sort((a, b) => a.order - b.order);
174
+ return obj.source.toSorted((a, b) => a.order - b.order);
165
175
  },
166
176
  children: (x) => solidJs.createMemo(() => x.children)
167
177
  });
@@ -179,8 +189,8 @@
179
189
  return props.children;
180
190
  }
181
191
  };
182
- obj.source.push(info);
183
- solidJs.onCleanup(() => obj.source.splice(obj.source.indexOf(store.createMutable(info)), 1));
192
+ exports2.Slot.push(obj.source, info);
193
+ solidJs.onCleanup(() => exports2.Slot.remove(obj.source, info));
184
194
  return solidJs.createComponent(solidJs.Show, {
185
195
  get when() {
186
196
  return !obj.attached;
@@ -219,13 +229,13 @@
219
229
  return solidJs.createMemo(() => content().reduceRight((a, b) => b(a), memo.children));
220
230
  }
221
231
  const IDENTITY = (x) => x;
222
- function bind(source, dest, to = IDENTITY) {
223
- const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => dest((prev) => to(x, prev)))), d2));
232
+ function bind(source, dest, to = IDENTITY, skip = false) {
233
+ const d = solidJs.createRoot((d2) => (solidJs.createRenderEffect(solidJs.on(source, (x) => skip ? skip = false : dest((prev) => to(x, prev)))), d2));
224
234
  return solidJs.onCleanup(d), d;
225
235
  }
226
236
  function bindTwoWay(source, dest, to, from) {
227
237
  const a = bind(source[0], dest[1], to);
228
- const b = bind(dest[0], source[1], from);
238
+ const b = bind(dest[0], source[1], from, true);
229
239
  return () => (a(), b());
230
240
  }
231
241
  function toSetter(get, set) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
@@ -34,6 +34,6 @@
34
34
  "switch",
35
35
  "case",
36
36
  "when",
37
- "debug"
37
+ "slot"
38
38
  ]
39
39
  }