Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": ["standard-with-typescript", "plugin:react/recommended"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react", "immutable"],
"rules": {
"immutable/no-mutation": "error",
"no-console": "error"
},
"ignorePatterns": ["node_modules/*", "dist/*", "/src/tests/*"] // Add the files or folders you want to exclude here
}
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
src
tsconfig.json
.babelrc
yarn.lock
.eslintrc.json
2 changes: 1 addition & 1 deletion dist/contexts/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="react" />
import { GXContextType } from "./types.js";
import { type GXContextType } from './types.js';
declare const GXContext: import("react").Context<GXContextType>;
export default GXContext;
1 change: 1 addition & 0 deletions dist/contexts/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/contexts/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 38 additions & 13 deletions dist/contexts/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
/// <reference types="react" />
import { GXAction } from "../providers/types.js";
export type GXSignalType<T = any> = {
import type IBuilderCase from '../interfaces/builderCase.js';
import { type GXAction } from '../providers/types.js';
/**
* Type that represents a signal
*/
export interface GXSignalType<T = any> {
name: string;
state: T;
actions: GXActionType<T>[];
operations?: GXOperationType<T>[];
};
export type GXActionType<T, P = any> = {
actions?: Array<GXActionType<T>>;
operations?: Array<GXOperationType<T>>;
asyncActions?: Array<GXAsyncActionType<T>>;
}
/**
* Type that represents Actions
*/
export interface GXActionType<T, P = any> {
type: string;
handler: (state: T, payload: P) => T;
};
export type GXOperationType<T, P = any, Q = any> = {
}
/**
* Type that represents operations
*/
export interface GXOperationType<T, P = any, Q = any> {
type: string;
handler: (state: T, payload: P) => Q;
};
export type DispatchedActionType = {
}
/**
* Type that represents async actions
*/
export interface GXAsyncActionType<T, P = any> {
type: string;
steps: IBuilderCase<T, P>;
}
/**
* Type of dispatched action
*/
export interface DispatchedActionType {
type: string;
payload: any;
};
export type GXContextType = {
}
/**
* Type of the signals context
*/
export interface GXContextType {
signals: GXSignalType[];
dispatch: React.Dispatch<GXAction>;
};
asyncDispatch: (action: GXAction) => any;
}
8 changes: 8 additions & 0 deletions dist/helpers/createAsyncAction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { type CreateAsyncActionProp, type CreateAsyncActionReturnType } from './types.js';
/**
* This function create an async action with different statuses
* @param handler Function that perform asynchronous task
* @returns
*/
declare const createAsyncAction: (handler: CreateAsyncActionProp) => CreateAsyncActionReturnType;
export default createAsyncAction;
18 changes: 18 additions & 0 deletions dist/helpers/createAsyncAction.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/helpers/createAsyncAction.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions dist/helpers/createSignal.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateSignalOptionType } from "./types.js";
import { GXActionType, GXOperationType } from "../contexts/types.js";
import { type CreateSignalOptionType } from './types.js';
import { type GXActionType, type GXAsyncActionType, type GXOperationType } from '../contexts/types.js';
/**
* Create a signal with a state and actions for managing this state
* @param options
Expand All @@ -10,5 +10,6 @@ declare const createSignal: <T>(options: CreateSignalOptionType<T>) => {
state: T;
actions: GXActionType<T, any>[];
operations: GXOperationType<T, any, any>[];
asyncActions: GXAsyncActionType<T, any>[];
};
export default createSignal;
22 changes: 17 additions & 5 deletions dist/helpers/createSignal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/helpers/createSignal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions dist/helpers/createStore.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { GXSignalType } from "../contexts/types.js";
import { CreateStoreType } from "./types.js";
import { type GXSignalType } from '../contexts/types.js';
import { type CreateStoreType } from './types.js';
/**
* Function that create a store by collection a list of signals
* @param signals List of signals
* @returns
*/
declare const createStore: (signals: GXSignalType[]) => CreateStoreType;
export default createStore;
7 changes: 6 additions & 1 deletion dist/helpers/createStore.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/helpers/createStore.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 39 additions & 11 deletions dist/helpers/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
import { GXSignalType } from "../contexts/types.js";
export type CreateSignalOptionType<T> = {
import { type GXSignalType } from '../contexts/types.js';
import { type Builder } from '../interfaces/builder.js';
import type IBuilderCase from '../interfaces/builderCase.js';
/**
* Type of the create signal option function
*/
export interface CreateSignalOptionType<T> {
name: string;
state: T;
actions: Action<T>;
actions?: Action<T>;
operations?: Operation<T>;
};
export type CreateStoreType = {
asyncActions?: AsyncAction<T>;
}
/**
* Type of the returned data of create store function
*/
export interface CreateStoreType {
getSignals: () => GXSignalType[];
}
/**
* Type of Action
*/
export type Action<T> = Record<string, (state: T, payload: any) => T>;
/**
* Type of Operation
*/
export type Operation<T> = Record<string, (state: T, payload?: any) => any>;
/**
* Type of Async Action
*/
export type AsyncAction<T> = (builder: Builder<T>) => Record<string, IBuilderCase<T>>;
export type CreateAsyncActionProp = (payload?: any) => Promise<any>;
export interface CreateAsyncActionReturnType {
pending: AsyncActionStatusesType;
fulfilled: AsyncActionStatusesType;
rejected: AsyncActionStatusesType;
handler: CreateAsyncActionProp;
}
export declare const AsyncActionStatuses: {
readonly PENDING: "PENDING";
readonly FULFILLED: "FULFILLED";
readonly REJECTED: "REJECTED";
};
export type Action<T> = {
[key: string]: (state: T, payload: any) => T;
};
export type Operation<T> = {
[key: string]: (state: T, payload?: any) => any;
};
export type AsyncActionStatusesType = (typeof AsyncActionStatuses)[keyof typeof AsyncActionStatuses];
6 changes: 6 additions & 0 deletions dist/helpers/types.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/helpers/types.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions dist/hooks/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export type Actions = {
[key: string]: (payload?: any) => void;
};
export type Operations<P = any> = {
[key: string]: (payload?: any) => P;
};
import { type AsyncActionStatusesType } from '../helpers/types';
export type Actions = Record<string, (payload?: any) => void>;
export type AsyncActions<T> = Record<string, (payload?: any) => Promise<{
data: T;
status: Omit<AsyncActionStatusesType, 'PENDING'>;
}>>;
export type Operations<P = any> = Record<string, (payload?: any) => P>;
2 changes: 1 addition & 1 deletion dist/hooks/useAction.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Actions } from "./types.js";
import { type Actions } from './types.js';
declare const useAction: <T = Actions>(signalName: string, action: string) => any;
export default useAction;
10 changes: 6 additions & 4 deletions dist/hooks/useAction.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/hooks/useAction.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/hooks/useActions.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Actions } from "./types.js";
import { type Actions } from './types.js';
declare const useActions: <T = Actions>(signalName: string, ...actions: string[]) => T;
export default useActions;
12 changes: 7 additions & 5 deletions dist/hooks/useActions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading