rask-ui 0.10.0 → 0.10.2

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/README.md CHANGED
@@ -328,7 +328,7 @@ function Example() {
328
328
 
329
329
  #### `assignState<T>(state, newState)`
330
330
 
331
- Merges properties from a new state object into an existing reactive state object. This is a convenience function that uses `Object.assign` internally.
331
+ Merges properties from a new state object into an existing reactive state object. Returns the updated state object.
332
332
 
333
333
  ```tsx
334
334
  import { assignState, createState } from "rask-ui";
@@ -341,7 +341,7 @@ function Example() {
341
341
  });
342
342
 
343
343
  const updateProfile = (updates) => {
344
- assignState(state, updates);
344
+ return assignState(state, updates);
345
345
  };
346
346
 
347
347
  return () => (
@@ -360,9 +360,11 @@ function Example() {
360
360
  - `state: T` - The reactive state object to update
361
361
  - `newState: T` - Object with properties to merge into the state
362
362
 
363
+ **Returns:** The updated state object (same reference as input state)
364
+
363
365
  **Notes:**
364
366
 
365
- - Equivalent to `Object.assign(state, newState)`
367
+ - Equivalent to `Object.assign(state, newState)` - returns the state for chaining
366
368
  - Triggers reactivity for all updated properties
367
369
  - Useful for bulk state updates from form data or API responses
368
370
 
@@ -724,10 +726,12 @@ function Child() {
724
726
 
725
727
  ### Async Data Management
726
728
 
727
- #### `createTask<T, P>(task)`
729
+ #### `createTask<P, T>(task)`
728
730
 
729
731
  A low-level reactive primitive for managing any async operation. `createTask` provides the foundation for building data fetching, mutations, polling, debouncing, and any other async pattern you need. It gives you full control without prescribing specific patterns.
730
732
 
733
+ The `Task<T, P>` type is also exported for type annotations (result type first, params type second).
734
+
731
735
  ```tsx
732
736
  import { createTask, createState } from "rask-ui";
733
737
 
@@ -870,12 +874,26 @@ createTask<T>(task: () => Promise<T>): Task<T, never> & {
870
874
  }
871
875
 
872
876
  // Task with parameters - manual control
873
- createTask<T, P>(task: (params: P) => Promise<T>): Task<T, P> & {
877
+ createTask<P, T>(task: (params: P) => Promise<T>): Task<T, P> & {
874
878
  run(params: P): Promise<T>;
875
879
  rerun(params: P): Promise<T>;
876
880
  }
877
881
  ```
878
882
 
883
+ **Task Type:**
884
+
885
+ The `Task` type is exported and can be used for type annotations:
886
+
887
+ ```tsx
888
+ import { Task } from "rask-ui";
889
+
890
+ // Task that returns a string, no parameters
891
+ const myTask: Task<string>;
892
+
893
+ // Task that returns a User object, accepts a number parameter
894
+ const myTask: Task<User, number>;
895
+ ```
896
+
879
897
  **Returns:** Task object with reactive state and methods:
880
898
 
881
899
  **State Properties:**
@@ -1,4 +1,4 @@
1
- export declare function assignState<T extends object>(state: T, newState: T): void;
1
+ export declare function assignState<T extends object>(state: T, newState: T): T;
2
2
  /**
3
3
  * Creates a reactive state object that tracks property access and notifies observers on changes.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"createState.d.ts","sourceRoot":"","sources":["../src/createState.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,QAElE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEzD;AAGD,eAAO,MAAM,YAAY,eAAoB,CAAC"}
1
+ {"version":3,"file":"createState.d.ts","sourceRoot":"","sources":["../src/createState.ts"],"names":[],"mappings":"AAGA,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAElE;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAEzD;AAGD,eAAO,MAAM,YAAY,eAAoB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { INSPECT_MARKER, INSPECTOR_ENABLED } from "./inspect";
2
2
  import { getCurrentObserver, Signal } from "./observation";
3
3
  export function assignState(state, newState) {
4
- Object.assign(state, newState);
4
+ return Object.assign(state, newState);
5
5
  }
6
6
  /**
7
7
  * Creates a reactive state object that tracks property access and notifies observers on changes.
@@ -1,4 +1,4 @@
1
- export type Task<T, P> = {
1
+ export type Task<P, T> = {
2
2
  isRunning: false;
3
3
  params: null;
4
4
  result: null;
@@ -23,7 +23,7 @@ export declare function createTask<T>(task: () => Promise<T>): Task<T, never> &
23
23
  run(): Promise<T>;
24
24
  rerun(): Promise<T>;
25
25
  };
26
- export declare function createTask<T, P>(task: (params: P) => Promise<T>): Task<T, P> & {
26
+ export declare function createTask<P, T>(task: (params: P) => Promise<T>): Task<T, P> & {
27
27
  run(params: P): Promise<T>;
28
28
  rerun(params: P): Promise<T>;
29
29
  };
@@ -1,4 +1,4 @@
1
- import { createState } from "./createState";
1
+ import { assignState, createState } from "./createState";
2
2
  export function createTask(task) {
3
3
  const state = createState({
4
4
  isRunning: false,
@@ -6,9 +6,6 @@ export function createTask(task) {
6
6
  error: null,
7
7
  params: null,
8
8
  });
9
- const assign = (newState) => {
10
- Object.assign(state, newState);
11
- };
12
9
  let currentAbortController;
13
10
  const fetch = (params) => {
14
11
  currentAbortController?.abort();
@@ -19,7 +16,7 @@ export function createTask(task) {
19
16
  if (abortController.signal.aborted) {
20
17
  return;
21
18
  }
22
- assign({
19
+ assignState(state, {
23
20
  isRunning: false,
24
21
  result,
25
22
  error: null,
@@ -30,7 +27,7 @@ export function createTask(task) {
30
27
  if (abortController.signal.aborted) {
31
28
  return;
32
29
  }
33
- assign({
30
+ assignState(state, {
34
31
  isRunning: false,
35
32
  result: null,
36
33
  error: String(error),
@@ -54,7 +51,7 @@ export function createTask(task) {
54
51
  },
55
52
  run(params) {
56
53
  const promise = fetch(params);
57
- assign({
54
+ assignState(state, {
58
55
  isRunning: true,
59
56
  result: null,
60
57
  error: null,
@@ -64,7 +61,7 @@ export function createTask(task) {
64
61
  },
65
62
  rerun(params) {
66
63
  const promise = fetch(params);
67
- assign({
64
+ assignState(state, {
68
65
  isRunning: true,
69
66
  result: state.result,
70
67
  error: null,
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { render } from "./render";
2
2
  export { createCleanup, createMountEffect, RaskStatefulComponent, RaskStatelessComponent, } from "./component";
3
3
  export { createContext } from "./createContext";
4
4
  export { createState, assignState } from "./createState";
5
- export { createTask } from "./createTask";
5
+ export { createTask, Task } from "./createTask";
6
6
  export { ErrorBoundary } from "./error";
7
7
  export { createRef } from "inferno";
8
8
  export { createView } from "./createView";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,GACV,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,GACV,MAAM,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rask-ui",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",