Skip to content

Commit fe51cdf

Browse files
authored
Merge pull request #10 from react-gx/dev
ADD: Adding Async State to GX
2 parents 4f7ad2a + cd4ed14 commit fe51cdf

Some content is hidden

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

71 files changed

+2082
-284
lines changed

.eslintrc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": ["standard-with-typescript", "plugin:react/recommended"],
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"plugins": ["react", "immutable"],
13+
"rules": {
14+
"immutable/no-mutation": "error",
15+
"no-console": "error"
16+
},
17+
"ignorePatterns": ["node_modules/*", "dist/*", "/src/tests/*"] // Add the files or folders you want to exclude here
18+
}

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
node_modules
22
src
33
tsconfig.json
4+
.babelrc
5+
yarn.lock
6+
.eslintrc.json

dist/contexts/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/// <reference types="react" />
2-
import { GXContextType } from "./types.js";
2+
import { type GXContextType } from './types.js';
33
declare const GXContext: import("react").Context<GXContextType>;
44
export default GXContext;

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: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
/// <reference types="react" />
2-
import { GXAction } from "../providers/types.js";
3-
export type GXSignalType<T = any> = {
2+
import type IBuilderCase from '../interfaces/builderCase.js';
3+
import { type GXAction } from '../providers/types.js';
4+
/**
5+
* Type that represents a signal
6+
*/
7+
export interface GXSignalType<T = any> {
48
name: string;
59
state: T;
6-
actions: GXActionType<T>[];
7-
operations?: GXOperationType<T>[];
8-
};
9-
export type GXActionType<T, P = any> = {
10+
actions?: Array<GXActionType<T>>;
11+
operations?: Array<GXOperationType<T>>;
12+
asyncActions?: Array<GXAsyncActionType<T>>;
13+
}
14+
/**
15+
* Type that represents Actions
16+
*/
17+
export interface GXActionType<T, P = any> {
1018
type: string;
1119
handler: (state: T, payload: P) => T;
12-
};
13-
export type GXOperationType<T, P = any, Q = any> = {
20+
}
21+
/**
22+
* Type that represents operations
23+
*/
24+
export interface GXOperationType<T, P = any, Q = any> {
1425
type: string;
1526
handler: (state: T, payload: P) => Q;
16-
};
17-
export type DispatchedActionType = {
27+
}
28+
/**
29+
* Type that represents async actions
30+
*/
31+
export interface GXAsyncActionType<T, P = any> {
32+
type: string;
33+
steps: IBuilderCase<T, P>;
34+
}
35+
/**
36+
* Type of dispatched action
37+
*/
38+
export interface DispatchedActionType {
1839
type: string;
1940
payload: any;
20-
};
21-
export type GXContextType = {
41+
}
42+
/**
43+
* Type of the signals context
44+
*/
45+
export interface GXContextType {
2246
signals: GXSignalType[];
2347
dispatch: React.Dispatch<GXAction>;
24-
};
48+
asyncDispatch: (action: GXAction) => any;
49+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { type CreateAsyncActionProp, type 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { CreateSignalOptionType } from "./types.js";
2-
import { GXActionType, GXOperationType } from "../contexts/types.js";
1+
import { type CreateSignalOptionType } from './types.js';
2+
import { type GXActionType, type GXAsyncActionType, type 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;

0 commit comments

Comments
 (0)