Skip to content

Commit

Permalink
Update libs, cleanup. (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
offbeatful authored Jul 22, 2021
1 parent 20aec29 commit 851bfe6
Show file tree
Hide file tree
Showing 9 changed files with 1,979 additions and 2,618 deletions.
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ stages:
- task: GitHubRelease@1
displayName: "Update GitHub release"
inputs:
gitHubConnection: "mocoding-software"
gitHubConnection: "github.com_offbeatful"
repositoryName: "mocoding-software/redux-automata"
action: edit
tag: "v$(Build.BuildNumber)"
Expand Down
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@
],
"homepage": "https://github.com/mocoding-software/redux-automata#readme",
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-object-rest-spread": "^7.9.6",
"@babel/plugin-transform-runtime": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@babel/preset-typescript": "^7.9.0",
"@types/jest": "^25.2.1",
"@types/node": "^13.13.5",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"eslint": "^7.0.0",
"eslint-config-prettier": "^6.11.0",
"@babel/core": "^7.14.8",
"@babel/plugin-proposal-object-rest-spread": "^7.14.7",
"@babel/plugin-transform-runtime": "^7.14.5",
"@babel/preset-env": "^7.14.8",
"@babel/preset-typescript": "^7.14.5",
"@types/jest": "^26.0.24",
"@types/node": "^16.4.0",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-only-warn": "^1.0.2",
"eslint-plugin-prettier": "^3.1.3",
"jest": "^26.0.1",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"jest-sonar-reporter": "^2.0.0",
"prettier": "^2.0.5",
"prettier": "^2.3.2",
"rimraf": "^3.0.2",
"rollup": "^2.8.0",
"rollup": "^2.53.3",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-typescript2": "^0.27.1",
"ts-jest": "^26.0.0",
"typescript": "^3.9.2"
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"ts-jest": "^27.0.4",
"typescript": "^4.3.5"
},
"dependencies": {
"@babel/runtime": "^7.9.6",
"redux": "^4.0.5"
"@babel/runtime": "^7.14.8",
"redux": "^4.1.0"
},
"jestSonar": {
"reportPath": ".coverage",
Expand Down
1 change: 0 additions & 1 deletion src/core/Automata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class Automata<TState> implements StateMachineOptions<TState> {
if (!existingState) throw new Error("State should be previously defined using this.state(...) method.");

this.initial = Object.assign(state({} as TState, undefined), {
// eslint-disable-next-line @typescript-eslint/camelcase
__sm_state: existingState.stateName,
});
}
Expand Down
29 changes: 15 additions & 14 deletions src/core/automataMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ import { ACTION_TYPE_PREFIX, ActionPayload, PayloadAction } from "./common";
export function automataMiddleware<D extends Redux.Dispatch, S>(
api: Redux.MiddlewareAPI<D, S>,
): (next: Redux.Dispatch) => Redux.Dispatch {
return (next: Redux.Dispatch) => <A extends PayloadAction<ActionPayload>>(action: A) => {
if (!action.type.startsWith(ACTION_TYPE_PREFIX)) return next(action);
return (next: Redux.Dispatch) =>
<A extends PayloadAction<ActionPayload>>(action: A) => {
if (!action.type.startsWith(ACTION_TYPE_PREFIX)) return next(action);

let dispatching = true;
let dispatching = true;

Object.assign(action, {
dispatch: <DispatchedAction extends Redux.Action>(a: DispatchedAction): DispatchedAction => {
if (dispatching) setTimeout(() => api.dispatch(a), 0);
else return api.dispatch(a);
return a;
},
});
Object.assign(action, {
dispatch: <DispatchedAction extends Redux.Action>(a: DispatchedAction): DispatchedAction => {
if (dispatching) setTimeout(() => api.dispatch(a), 0);
else return api.dispatch(a);
return a;
},
});

const deferred = next(action);
dispatching = false;
return deferred;
};
const deferred = next(action);
dispatching = false;
return deferred;
};
}
5 changes: 2 additions & 3 deletions src/core/automataReducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Redux from "redux";
import { Automata } from "./Automata";
import { ACTION_TYPE_PREFIX, ActionPayload, AutomataState, LocalStore } from "./common";
import { ACTION_TYPE_PREFIX, AutomataState, LocalStore } from "./common";

export function automataReducer<TState>(automata: Automata<TState>): Redux.Reducer<TState> {
if (automata.initial.__sm_state === undefined)
Expand All @@ -13,7 +13,7 @@ export function automataReducer<TState>(automata: Automata<TState>): Redux.Reduc

if (!currentNode) throw new Error("Can't find initial state.");

return <TPayload extends ActionPayload>(state: AutomataState<TState> = automata.initial, action: Redux.AnyAction) => {
return (state: AutomataState<TState> = automata.initial, action: Redux.AnyAction) => {
// skip if not state machine;
if (typeof action.type !== "string" || !action.type.startsWith(ACTION_TYPE_PREFIX)) return state;

Expand All @@ -31,7 +31,6 @@ export function automataReducer<TState>(automata: Automata<TState>): Redux.Reduc

automata.current = state;
newState = nextNode.entry(state, action.payload);
// eslint-disable-next-line @typescript-eslint/camelcase
newState.__sm_state = nextNode.entry.stateName;
automata.current = newState;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/options/ActionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { Arc, ArcCreator } from "./common";
import { StateOptionsEx } from "./StateOptionsEx";

export class ActionOptions<TState, TAction>
implements ActionFluentOptions<TState, TAction>, ArcCreator<TState, TAction> {
implements ActionFluentOptions<TState, TAction>, ArcCreator<TState, TAction>
{
private transitions: TransitionMethod<TState, TAction>[] = [];
private targetState?: string;

Expand Down
4 changes: 2 additions & 2 deletions src/task-automata/createTaskAutomation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TaskAutomation<
TResult,
TInput = void,
TError extends Error = Error,
TState extends TaskState<TResult, TError> = TaskState<TResult, TError>
TState extends TaskState<TResult, TError> = TaskState<TResult, TError>,
> {
reducer: Redux.Reducer<TState>;
start: ActionDefinition<TInput>;
Expand All @@ -19,7 +19,7 @@ export function createTaskAutomation<
TResult,
TInput = void,
TError extends Error = Error,
TState extends TaskState<TResult, TError> = TaskState<TResult, TError>
TState extends TaskState<TResult, TError> = TaskState<TResult, TError>,
>(
dataName: string,
processTask: Task<TResult, TInput>,
Expand Down
2 changes: 1 addition & 1 deletion test/noop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Noop", () => {
test("On Execute Test", () => {
store.dispatch(UpdateMessage());

return new Promise((accept) => setTimeout(accept, 1)).then(() => {
return new Promise((accept) => setTimeout(accept, 1, undefined)).then(() => {
const currentState = store.getState() as AutomataState<TestState>;
expect(currentState.__sm_state).toBe(Active.stateName);
});
Expand Down
Loading

0 comments on commit 851bfe6

Please sign in to comment.