Skip to content

Commit

Permalink
chore: fix some trivial issues (#40)
Browse files Browse the repository at this point in the history
* chore: upgrade deps

* chore: upgrade husky to v8

* fix: eslint issues

* chore: fix typos
  • Loading branch information
xuchaobei authored Jun 14, 2022
1 parent fafffd0 commit 4509cf9
Show file tree
Hide file tree
Showing 33 changed files with 124 additions and 88 deletions.
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no-install lint-staged
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ public-hoist-pattern[]=@modern-js/eslint-config
public-hoist-pattern[]=@modern-js-app/eslint-config
public-hoist-pattern[]=@babel/eslint-plugin
public-hoist-pattern[]=@typescript-eslint/eslint-plugin
public-hoist-pattern[]=@modern-js/tsconfig
public-hoist-pattern[]=@commitlint/cli
public-hoist-pattern[]=lint-staged
public-hoist-pattern[]=eslint
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@
},
"emmet.triggerExpansionOnTab": true,
"typescript.tsdk": "node_modules/typescript/lib",
"deno.enable": false
"deno.enable": false,
"cSpell.words": ["immer", "middlewares", "reduck", "xstate"]
}
20 changes: 8 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
"change": "modern change",
"bump": "modern bump",
"pre": "modern pre",
"release": "modern release"
"release": "modern release",
"prepare": "husky install"
},
"engines": {
"node": ">=12.13.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
Expand Down Expand Up @@ -64,11 +59,12 @@
]
},
"devDependencies": {
"@modern-js/monorepo-tools": "latest",
"@modern-js/plugin-jarvis": "latest",
"@modern-js/tsconfig": "latest",
"@commitlint/config-conventional": "^13.2.0",
"@commitlint/cli": "^13.2.0",
"@commitlint/cli": "^17.0.0",
"@commitlint/config-conventional": "^17.0.0",
"@modern-js/monorepo-tools": "^1.4.6",
"@modern-js/plugin-jarvis": "^1.2.12",
"@modern-js/tsconfig": "^1.2.0",
"husky": "^8.0.0",
"webpack": "^5.54.0"
}
}
6 changes: 3 additions & 3 deletions packages/plugins/auto-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
"@babel/runtime": "^7"
},
"devDependencies": {
"@modern-js/module-tools": "latest",
"@modern-js/plugin-testing": "latest",
"@modern-js-reduck/store": "^1.0.1",
"@types/jest": "^26",
"@modern-js/module-tools": "^1.5.3",
"@modern-js/plugin-testing": "^1.5.5",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const testModel = model('name').define({
const testModel1 = model('name1').define({
state: 0,
actions: {
setState(_state, payload) {
setState(_state, payload: number) {
return payload + 1;
},
},
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/auto-actions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { ArrayDispatchActions } from './array';
import * as arrayActions from './array';
import { ObjectDispatchActions, createObjectActions } from './object';

type ExractDispatchAction<T, State> = {
type ExtractDispatchAction<T, State> = {
[key in keyof T]: T[key] extends (state: any) => any
? () => void
: T[key] extends (state: any, payload: any) => any
? (paylod: State) => void
? (payload: State) => void
: never;
};

Expand All @@ -25,7 +25,7 @@ declare module '@modern-js-reduck/store' {
| ((...args: any[]) => any)
| RegExp
| symbol
? ExractDispatchAction<typeof primitiveActions, M['_']['state']>
? ExtractDispatchAction<typeof primitiveActions, M['_']['state']>
: M['_']['state'] extends any[]
? ArrayDispatchActions<M['_']['state']>
: M['_']['state'] extends Record<string, any>
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/devtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"redux": "^4.1.1"
},
"devDependencies": {
"@modern-js/module-tools": "latest",
"@modern-js/plugin-testing": "latest",
"@modern-js-reduck/store": "^1.0.4",
"@types/jest": "^26",
"@modern-js/module-tools": "^1.5.3",
"@modern-js/plugin-testing": "^1.5.5",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
Expand Down
10 changes: 5 additions & 5 deletions packages/plugins/effects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
},
"dependencies": {
"@babel/runtime": "^7",
"redux": "^4.1.1",
"redux-promise-middleware": "^6.1.2",
"redux-thunk": "^2.3.0",
"redux": "^4.1.1"
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"@modern-js-reduck/store": "^1.0.1",
"@modern-js/module-tools": "latest",
"@modern-js/plugin-testing": "latest",
"@types/jest": "^26",
"@modern-js/module-tools": "^1.5.3",
"@modern-js/plugin-testing": "^1.5.5",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
Expand Down
1 change: 0 additions & 1 deletion packages/plugins/effects/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line filenames/match-exported
import plugin from './plugin';

export { plugin };
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/effects/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Effects {
}

declare module '@modern-js-reduck/store' {
// Add `effects` type when use model({effets}).
// Add `effects` type when use model({effects}).
interface ModelDesc {
effects?: Effects;
}
Expand All @@ -24,7 +24,7 @@ declare module '@modern-js-reduck/store' {
}

/**
* Generare dispatch action from effects definations.
* Generate dispatch action from effects definitions.
*/
const createDispatchActionsFromEffects = (
store: any,
Expand All @@ -47,7 +47,7 @@ const createDispatchActionsFromEffects = (
});

// Handled by promise middleware or redux thunk
// Otherwise, do not dispatch action, just exec the effect fuction.
// Otherwise, do not dispatch action, just exec the effect function.
if (value instanceof Promise || typeof value === 'function') {
return dispatch(value);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/immer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
"immer": "^9.0.5"
},
"devDependencies": {
"@modern-js/module-tools": "latest",
"@modern-js/plugin-testing": "latest",
"@modern-js-reduck/store": "^1.0.1",
"@types/jest": "^26",
"@modern-js/module-tools": "^1.5.3",
"@modern-js/plugin-testing": "^1.5.5",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
Expand Down
8 changes: 4 additions & 4 deletions packages/plugins/xstate-immer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@
},
"dependencies": {
"@babel/runtime": "^7",
"@xstate/immer": "^0.2.0",
"@xstate/immer": "^0.3.1",
"immer": "^9.0.5"
},
"devDependencies": {
"@modern-js/module-tools": "latest",
"@modern-js/plugin-testing": "latest",
"@modern-js-reduck/plugin-xstate": "^1.0.1",
"@modern-js-reduck/react": "^1.0.1",
"@modern-js-reduck/store": "^1.0.1",
"@modern-js/module-tools": "^1.5.3",
"@modern-js/plugin-testing": "^1.5.5",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@types/jest": "^26",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/xstate-immer/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const plugin = createPlugin(() => ({
return modelDesc;

/**
* tranverse for immerifing actions
* traverse for immerifing actions
*/
function traverse(obj: any) {
Object.keys(obj).forEach(key => {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/xstate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
"xstate": "^4.23.1"
},
"devDependencies": {
"@modern-js/module-tools": "latest",
"@modern-js/plugin-testing": "latest",
"@modern-js-reduck/react": "^1.0.1",
"@modern-js-reduck/store": "^1.0.4",
"@modern-js/module-tools": "^1.5.3",
"@modern-js/plugin-testing": "^1.5.5",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@types/jest": "^26",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/xstate/src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export function mergeMachineMap(
map: MachineMap,
modelDesc: MachineModelDesc,
): void {
// FIXME: mounting model must have name, shoudle fix it's type
// FIXME: mounting model must have name, should fix it's type
const modelName = modelDesc.name;

// warning for replacing service
const prevService = map[modelName];
if (prevService) {
console.warn(
`Mounting a model <${modelName}> with existed service. The service would be overrided.`,
`Mounting a model <${modelName}> with existed service. The service would be overridden.`,
);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
"invariant": "^2.2.4"
},
"devDependencies": {
"@modern-js/module-tools": "latest",
"@modern-js/plugin-testing": "latest",
"@modern-js/module-tools": "^1.5.3",
"@modern-js/plugin-testing": "^1.5.5",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.0.0",
"@types/invariant": "^2.2.34",
"@types/jest": "^26",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
Expand Down
14 changes: 7 additions & 7 deletions packages/react/src/batchManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ const combineSubscribe = (
return (handler: () => void) => {
handlers.add(handler);

const disposelist: any[] = [];
const disposer: any[] = [];

subscribes.forEach(subscribe => {
disposelist.push(
disposer.push(
subscribe(() => {
changed = true;
}),
);
});

const unsubsribeStore = store.subscribe(() => {
const unsubscribeStore = store.subscribe(() => {
if (changed) {
handlers.forEach(() => handler());
}
Expand All @@ -33,8 +33,8 @@ const combineSubscribe = (
});

return () => {
unsubsribeStore();
disposelist.forEach(dispose => dispose());
unsubscribeStore();
disposer.forEach(dispose => dispose());
};
};
};
Expand All @@ -47,7 +47,7 @@ const createBatchManager = (store: Store) => {
const updateList: (() => void)[] = [];

// listen to models in using
const setupSubsribe = () => {
const setupSubscribe = () => {
if (typeof unsubscribe === 'function') {
unsubscribe();
}
Expand Down Expand Up @@ -101,7 +101,7 @@ const createBatchManager = (store: Store) => {
}
});

setupSubsribe();
setupSubscribe();
};

// add models to listen
Expand Down
12 changes: 6 additions & 6 deletions packages/react/src/createApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const createApp = (config: Config) => {
const lastValueRef = useRef<ReturnType<typeof store.use>>(initialValue);

useEffect(() => {
const unsubsribe = initialValue[2](() => {
const unsubscribe = initialValue[2](() => {
const newValue = store.use(...args);

if (
Expand All @@ -80,7 +80,7 @@ const createApp = (config: Config) => {
batchManager.addModels(...args);

return () => {
unsubsribe();
unsubscribe();
batchManager.removeModels(...args);
};
}, []);
Expand Down Expand Up @@ -112,7 +112,7 @@ const createApp = (config: Config) => {
const { store } = context;
const [state, actions, subscribe] = useMemo(() => store.use(...args), []);
const value = useRef<ReturnType<UseModel> | any>([
// deep clone state in case mutate origin state accidentlly.
// deep clone state in case mutate origin state accidentally.
JSON.parse(JSON.stringify(state)),
actions,
subscribe,
Expand Down Expand Up @@ -143,14 +143,14 @@ const createApp = (config: Config) => {
const finalConfig = configFromProvider || config;

const localStoreConfig = {
enhanders: finalConfig?.enhancers || [],
enhancers: finalConfig?.enhancers || [],
middlewares: finalConfig?.middlewares || [],
plugins: finalConfig?.plugins,
};

const reuckStore = createStore(localStoreConfig);
const reduckStore = createStore(localStoreConfig);

return [reuckStore, createBatchManager(reuckStore)];
return [reduckStore, createBatchManager(reduckStore)];
}, []);

return useMemo(() => createUseModel(store, batchManager), [])(...args);
Expand Down
10 changes: 5 additions & 5 deletions packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
"redux": "^4.1.1"
},
"devDependencies": {
"tsd": "latest",
"@modern-js/module-tools": "latest",
"@modern-js/plugin-testing": "latest",
"@modern-js/runtime": "latest",
"@types/jest": "^26",
"@modern-js/module-tools": "^1.5.3",
"@modern-js/plugin-testing": "^1.5.5",
"@modern-js/runtime": "^1.3.0",
"@types/jest": "^27.5.1",
"@types/node": "^14",
"@types/react": "^17",
"@types/react-dom": "^17",
"tsd": "latest",
"typescript": "latest"
},
"modernSettings": {},
Expand Down
Loading

0 comments on commit 4509cf9

Please sign in to comment.