@solidjs/signals 0.0.2 → 0.0.3

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.
@@ -4,4 +4,5 @@ export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, late
4
4
  export { Effect, EagerComputation } from "./effect.js";
5
5
  export { flushSync, createBoundary, type IQueue, Queue } from "./scheduler.js";
6
6
  export { createSuspense } from "./suspense.js";
7
+ export { SUPPORTS_PROXY } from "./constants.js";
7
8
  export * from "./flags.js";
@@ -1,4 +1,4 @@
1
- export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, createSuspense } from "./core/index.js";
1
+ export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, createSuspense, SUPPORTS_PROXY } from "./core/index.js";
2
2
  export type { ErrorHandler, SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
3
3
  export { mapArray, type Maybe } from "./map.js";
4
4
  export * from "./signals.js";
@@ -1,12 +1,13 @@
1
1
  import type { Accessor } from "./signals.js";
2
2
  export type Maybe<T> = T | void | null | undefined | false;
3
3
  /**
4
- * Reactive map helper that caches each list item by reference to reduce unnecessary mapping on
5
- * updates.
4
+ * Reactively transforms an array with a callback function - underlying helper for the `<For>` control flow
6
5
  *
7
- * @see {@link https://github.com/solidjs/x-reactivity#maparray}
6
+ * similar to `Array.prototype.map`, but gets the value and index as accessos, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
7
+ *
8
+ * @description https://docs.solidjs.com/reference/reactive-utilities/map-array
8
9
  */
9
10
  export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
10
11
  keyed?: boolean | ((item: Item) => any);
11
- name?: string;
12
+ fallback: Accessor<any>;
12
13
  }): Accessor<MappedItem[]>;
@@ -1,21 +1,38 @@
1
1
  import type { SignalOptions } from "./core/index.js";
2
2
  import { Owner } from "./core/index.js";
3
- export interface Accessor<T> {
4
- (): T;
5
- }
6
- export interface Setter<T> {
7
- (value: T | SetValue<T>): T;
8
- }
9
- export interface SetValue<T> {
10
- (currentValue: T): T;
11
- }
12
- export type Signal<T> = [read: Accessor<T>, write: Setter<T>];
3
+ export type Accessor<T> = () => T;
4
+ export type Setter<in out T> = {
5
+ <U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((prev: T) => U)]): undefined extends T ? undefined : U;
6
+ <U extends T>(value: (prev: T) => U): U;
7
+ <U extends T>(value: Exclude<U, Function>): U;
8
+ <U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U;
9
+ };
10
+ export type Signal<T> = [get: Accessor<T>, set: Setter<T>];
13
11
  /**
14
- * Wraps the given value into a signal. The signal will return the current value when invoked
15
- * `fn()`, and provide a simple write API via `write()`. The value can now be observed
16
- * when used inside other computations created with `computed` and `effect`.
12
+ * Creates a simple reactive state with a getter and setter
13
+ * ```typescript
14
+ * const [state: Accessor<T>, setState: Setter<T>] = createSignal<T>(
15
+ * value: T,
16
+ * options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) }
17
+ * )
18
+ * ```
19
+ * @param value initial value of the state; if empty, the state's type will automatically extended with undefined; otherwise you need to extend the type manually if you want setting to undefined not be an error
20
+ * @param options optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity
21
+ *
22
+ * @returns ```typescript
23
+ * [state: Accessor<T>, setState: Setter<T>]
24
+ * ```
25
+ * * the Accessor is a function that returns the current value and registers each call to the reactive root
26
+ * * the Setter is a function that allows directly setting or mutating the value:
27
+ * ```typescript
28
+ * const [count, setCount] = createSignal(0);
29
+ * setCount(count => count + 1);
30
+ * ```
31
+ *
32
+ * @description https://docs.solidjs.com/reference/basic-reactivity/create-signal
17
33
  */
18
- export declare function createSignal<T>(initialValue: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
34
+ export declare function createSignal<T>(): Signal<T | undefined>;
35
+ export declare function createSignal<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
19
36
  export declare function createSignal<T>(fn: (prev?: T) => T, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
20
37
  export declare function createAsync<T>(fn: (prev?: T) => Promise<T> | AsyncIterable<T> | T, initial?: T, options?: SignalOptions<T>): Accessor<T>;
21
38
  /**
@@ -1,4 +1,4 @@
1
- export type { Store, StoreSetter, StoreNode, NotWrappable } from "./store.js";
1
+ export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./store.js";
2
2
  export type { Merge, Omit } from "./utilities.js";
3
3
  export { unwrap, isWrappable, createStore, createProjection, $RAW, $TRACK, $PROXY, $TARGET } from "./store.js";
4
4
  export { reconcile } from "./reconcile.js";
@@ -1 +1 @@
1
- export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => void;
1
+ export declare function reconcile<T extends U, U>(value: T, key: string | ((item: NonNullable<any>) => any)): (state: U) => T;
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
- "license": "ISC",
5
+ "author": "Ryan Carniato",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/solidjs/signals"
10
+ },
6
11
  "type": "module",
7
12
  "main": "dist/node.cjs",
8
13
  "module": "dist/prod.js",