what-core 0.6.6 → 0.6.8

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/hooks.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ // What Framework - Hooks Type Definitions
2
+
3
+ import { Signal, Computed, Updater, VNodeChild } from './index.js';
4
+
5
+ export function useState<T>(initial: T | (() => T)): [Signal<T>, (value: Updater<T>) => void];
6
+ export function useSignal<T>(initial: T | (() => T)): Signal<T>;
7
+ export function useComputed<T>(fn: () => T): Computed<T>;
8
+ export function useEffect(fn: () => void | (() => void), deps?: any[]): void;
9
+ export function useMemo<T>(fn: () => T, deps?: any[]): Computed<T>;
10
+ export function useCallback<T extends (...args: any[]) => any>(fn: T, deps?: any[]): T;
11
+ export function useRef<T>(initial?: T): { current: T | undefined };
12
+ export function useContext<T>(context: { _defaultValue: T }): T;
13
+ export function createContext<T>(defaultValue?: T): { _defaultValue: T; Provider: (props: { value: T; children?: VNodeChild }) => VNodeChild; Consumer: (props: { children: (value: T) => VNodeChild }) => VNodeChild };
14
+ export function useReducer<S, A>(reducer: (state: S, action: A) => S, initialState: S, init?: (s: S) => S): [Signal<S>, (action: A) => void];
15
+ export function onMount(fn: () => void | (() => void)): void;
16
+ export function onCleanup(fn: () => void): void;
17
+
18
+ export function createResource<T = any, S = any>(
19
+ fetcher: (source?: S, ctx?: { signal: AbortSignal }) => Promise<T> | T,
20
+ options?: { initialValue?: T; source?: S },
21
+ ): [Signal<T | null>, {
22
+ loading: Signal<boolean>;
23
+ error: Signal<any>;
24
+ refetch: (source?: S) => Promise<any>;
25
+ mutate: (value: Updater<T | null>) => void;
26
+ }];
package/index.d.ts CHANGED
@@ -130,11 +130,11 @@ export function classList(el: Element, classes: Record<string, boolean | (() =>
130
130
 
131
131
  // --- Hooks ---
132
132
 
133
- export function useState<T>(initial: T | (() => T)): [T, (value: Updater<T>) => void];
133
+ export function useState<T>(initial: T | (() => T)): [Signal<T>, (value: Updater<T>) => void];
134
134
  export function useSignal<T>(initial: T | (() => T)): Signal<T>;
135
135
  export function useComputed<T>(fn: () => T): Computed<T>;
136
136
  export function useEffect(fn: () => void | (() => void), deps?: unknown[]): void;
137
- export function useMemo<T>(fn: () => T, deps?: unknown[]): T;
137
+ export function useMemo<T>(fn: () => T, deps?: unknown[]): Computed<T>;
138
138
  export function useCallback<T extends (...args: any[]) => any>(fn: T, deps?: unknown[]): T;
139
139
  export function useRef<T>(initial: T): { current: T };
140
140
 
@@ -149,7 +149,7 @@ export function useReducer<S, A>(
149
149
  reducer: (state: S, action: A) => S,
150
150
  initialState: S,
151
151
  init?: (initial: S) => S,
152
- ): [S, (action: A) => void];
152
+ ): [Signal<S>, (action: A) => void];
153
153
  export function onMount(fn: () => void): void;
154
154
  export function onCleanup(fn: () => void): void;
155
155
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-core",
3
- "version": "0.6.6",
3
+ "version": "0.6.8",
4
4
  "description": "What Framework - The closest framework to vanilla JS",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -33,6 +33,7 @@
33
33
  "import": "./src/testing.js"
34
34
  },
35
35
  "./hooks": {
36
+ "types": "./hooks.d.ts",
36
37
  "import": "./src/hooks.js"
37
38
  },
38
39
  "./compiler": {
@@ -53,6 +54,7 @@
53
54
  "jsx-runtime.d.ts",
54
55
  "render.d.ts",
55
56
  "testing.d.ts",
57
+ "hooks.d.ts",
56
58
  "compiler.d.ts",
57
59
  "devtools.d.ts"
58
60
  ],
package/src/index.js CHANGED
@@ -15,12 +15,16 @@ export { h, Fragment, html } from './h.js';
15
15
  // DOM mounting & rendering (fine-grained, no VDOM reconciler)
16
16
  export { mount } from './dom.js';
17
17
 
18
- // Hooks — Solid-style API (signal-first)
19
- // React-style hooks (useState, useEffect, useMemo, useCallback, useRef)
20
- // are available via 'what-framework/react-compat' only.
18
+ // Hooks — run-once component hooks backed by signals.
19
+ // useState returns a signal accessor plus setter; useMemo returns a computed signal.
21
20
  export {
21
+ useState,
22
22
  useSignal,
23
23
  useComputed,
24
+ useEffect,
25
+ useMemo,
26
+ useCallback,
27
+ useRef,
24
28
  useContext,
25
29
  useReducer,
26
30
  createContext,