solid-ctrl-flow 5.0.1 → 5.1.1

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
@@ -6,6 +6,12 @@ import { Owner } from 'solid-js';
6
6
  import { ParentProps } from 'solid-js';
7
7
  import { splitProps } from 'solid-js';
8
8
 
9
+ /** Minimal representation of an event target */
10
+ declare type AbstractEventTarget<K, F> = {
11
+ addEventListener(k: K, f: F): void;
12
+ removeEventListener(k: K, f: F): void;
13
+ };
14
+
9
15
  /** Like a {@link Match} but gets the value from the closest {@link On} ancestor */
10
16
  export declare function Case(props: ParentProps<{
11
17
  value: unknown;
@@ -151,6 +157,16 @@ export declare class OrderedLinkedListNode<T> extends OrderedLinkedList<T> {
151
157
  remove(): void;
152
158
  }
153
159
 
160
+ /**
161
+ * Adds the {@link f} event listener to the {@link k} event of the {@link obj} emitter and removes it when the current reactive context is disposed
162
+ * @param obj The emitter to which to add the event listener
163
+ * @param k The key of the event for which to add the listener
164
+ * @param f The function to call when the event is emitted
165
+ */
166
+ export declare function registerEventListener<K extends keyof HTMLElementEventMap>(obj: HTMLElement, type: K, listener: (this: HTMLElement, e: HTMLElementEventMap[K]) => any): void;
167
+
168
+ export declare function registerEventListener<K, F>(obj: AbstractEventTarget<K, F>, k: K, f: F): void;
169
+
154
170
  /**
155
171
  * Executes {@link f} with the provided value for the specified {@link Context}.
156
172
  * You can pass `undefined` to {@link value} in order to get back the default value for {@link ctx}.
package/dist/index.mjs CHANGED
@@ -1,8 +1,12 @@
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, onCleanup, createRoot, getOwner, createMemo, Show, createContext, useContext, For, createRenderEffect, on, splitProps, createSignal, 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));
5
5
  }
6
+ function registerEventListener(obj, k, f) {
7
+ obj.addEventListener(k, f);
8
+ onCleanup(() => obj.removeEventListener(k, f));
9
+ }
6
10
  function runWithContext(ctx2, value, f) {
7
11
  return createRoot((d) => {
8
12
  try {
@@ -270,6 +274,7 @@ export {
270
274
  SameContext,
271
275
  Spread,
272
276
  memoProps,
277
+ registerEventListener,
273
278
  runWithContext,
274
279
  splitAndMemoProps,
275
280
  untrackCall,
package/dist/index.umd.js CHANGED
@@ -5,6 +5,10 @@
5
5
  function untrackCall(f, ...args) {
6
6
  return solidJs.untrack(() => f.apply(this, args));
7
7
  }
8
+ function registerEventListener(obj, k, f) {
9
+ obj.addEventListener(k, f);
10
+ solidJs.onCleanup(() => obj.removeEventListener(k, f));
11
+ }
8
12
  function runWithContext(ctx2, value, f) {
9
13
  return solidJs.createRoot((d) => {
10
14
  try {
@@ -271,6 +275,7 @@
271
275
  exports2.SameContext = SameContext;
272
276
  exports2.Spread = Spread;
273
277
  exports2.memoProps = memoProps;
278
+ exports2.registerEventListener = registerEventListener;
274
279
  exports2.runWithContext = runWithContext;
275
280
  exports2.splitAndMemoProps = splitAndMemoProps;
276
281
  exports2.untrackCall = untrackCall;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solid-ctrl-flow",
3
- "version": "5.0.1",
3
+ "version": "5.1.1",
4
4
  "description": "Control flow components for solid-js",
5
5
  "author": "AFatNiBBa",
6
6
  "license": "ISC",
package/readMe.md CHANGED
@@ -233,5 +233,8 @@ Like `splitProps()` but passes the every part except the last one to [`memoProps
233
233
  ### `untrackCall()`
234
234
  Calls a function untracking what happens inside of it but not what gets passed as its argument
235
235
 
236
+ ### `registerEventListener()`
237
+ Adds an event listener and registers its removal
238
+
236
239
  ### `runWithContext()`
237
240
  Creates a context scope that persists for the duration of a function