Skip to content

Commit 00259a4

Browse files
committed
Add: Async State v1
1 parent 19bdceb commit 00259a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+935
-81
lines changed

dist/contexts/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/contexts/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/contexts/types.d.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
/// <reference types="react" />
2+
import IBuilderCase from "../interfaces/builderCase.js";
23
import { GXAction } from "../providers/types.js";
4+
/**
5+
* Type that represents a signal
6+
*/
37
export type GXSignalType<T = any> = {
48
name: string;
59
state: T;
6-
actions: GXActionType<T>[];
10+
actions?: GXActionType<T>[];
711
operations?: GXOperationType<T>[];
12+
asyncActions?: GXAsyncActionType<T>[];
813
};
14+
/**
15+
* Type that represents Actions
16+
*/
917
export type GXActionType<T, P = any> = {
1018
type: string;
1119
handler: (state: T, payload: P) => T;
1220
};
21+
/**
22+
* Type that represents operations
23+
*/
1324
export type GXOperationType<T, P = any, Q = any> = {
1425
type: string;
1526
handler: (state: T, payload: P) => Q;
1627
};
28+
/**
29+
* Type that represents async actions
30+
*/
31+
export type GXAsyncActionType<T, P = any> = {
32+
type: string;
33+
steps: IBuilderCase<T, P>;
34+
};
35+
/**
36+
* Type of dispatched action
37+
*/
1738
export type DispatchedActionType = {
1839
type: string;
1940
payload: any;
2041
};
42+
/**
43+
* Type of the signals context
44+
*/
2145
export type GXContextType = {
2246
signals: GXSignalType[];
2347
dispatch: React.Dispatch<GXAction>;
48+
asyncDispatch: (action: GXAction) => any;
2449
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { CreateAsyncActionProp, CreateAsyncActionReturnType } from "./types.js";
2+
/**
3+
* This function create an async action with different statuses
4+
* @param handler Function that perform asynchronous task
5+
* @returns
6+
*/
7+
declare const createAsyncAction: (handler: CreateAsyncActionProp) => CreateAsyncActionReturnType;
8+
export default createAsyncAction;

dist/helpers/createAsyncAction.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/helpers/createAsyncAction.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/helpers/createSignal.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CreateSignalOptionType } from "./types.js";
2-
import { GXActionType, GXOperationType } from "../contexts/types.js";
2+
import { GXActionType, GXAsyncActionType, GXOperationType } from "../contexts/types.js";
33
/**
44
* Create a signal with a state and actions for managing this state
55
* @param options
@@ -10,5 +10,6 @@ declare const createSignal: <T>(options: CreateSignalOptionType<T>) => {
1010
state: T;
1111
actions: GXActionType<T, any>[];
1212
operations: GXOperationType<T, any, any>[];
13+
asyncActions: GXAsyncActionType<T, any>[];
1314
};
1415
export default createSignal;

dist/helpers/createSignal.js

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/helpers/createSignal.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/helpers/createStore.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { GXSignalType } from "../contexts/types.js";
22
import { CreateStoreType } from "./types.js";
3+
/**
4+
* Function that create a store by collection a list of signals
5+
* @param signals List of signals
6+
* @returns
7+
*/
38
declare const createStore: (signals: GXSignalType[]) => CreateStoreType;
49
export default createStore;

0 commit comments

Comments
 (0)