Skip to content

Commit

Permalink
Merge pull request #12 from kuasha420/chore/update-deps
Browse files Browse the repository at this point in the history
Update ESLint and other dependencies
  • Loading branch information
kuasha420 authored Oct 15, 2024
2 parents 9959163 + 3ea0737 commit d83cf4c
Show file tree
Hide file tree
Showing 17 changed files with 414 additions and 3,240 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

4 changes: 0 additions & 4 deletions .eslintrc.js

This file was deleted.

22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
},
rules: {
...reactHooks.configs.recommended.rules,
},
}
);
34 changes: 15 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "mst-persistent-store",
"version": "3.1.1",
"description": "Mobx State Tree Persistant Store Provider Component and Consumer Hook writen in TypeScript",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -35,32 +36,27 @@
}
},
"scripts": {
"lint": "eslint . --ext .ts,.tsx",
"lint": "eslint",
"prepare": "rm -rf ./dist/* && tsc -p tsconfig.build.json",
"test": "vitest",
"type-check": "tsc"
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "7.21.11",
"@react-native-async-storage/async-storage": "1.21.0",
"@types/node": "20.10.3",
"@types/react": "18.2.42",
"@typescript-eslint/eslint-plugin": "6.13.2",
"@typescript-eslint/parser": "6.13.2",
"eslint": "8.55.0",
"eslint-config-react-app": "7.0.1",
"eslint-plugin-flowtype": "8.0.3",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"@eslint/js": "^9.11.1",
"@react-native-async-storage/async-storage": "2.0.0",
"@types/node": "22.7.5",
"@types/react": "18.3.11",
"eslint": "^9.11.1",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"localforage": "1.10.0",
"mobx": "6.12.0",
"mobx-state-tree": "5.4.0",
"prettier": "3.1.0",
"react": "18.2.0",
"typescript": "5.3.2",
"vitest": "2.1.1"
"mobx": "6.13.3",
"mobx-state-tree": "6.0.1",
"prettier": "3.3.3",
"react": "18.3.1",
"typescript": "5.6.3",
"typescript-eslint": "^8.7.0",
"vitest": "2.1.3"
},
"dependencies": {
"@hyperjump/json-pointer": "1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/hydration/hydrate-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const testSnapshot: SnapshotIn<TestStoreModel> = {
const simpleSnapshotModifier = (
snapshot: SnapshotIn<TestStoreModel>,
key?: keyof SnapshotIn<TestStoreModel>,
value?: any
value?: unknown
) => {
const updatedSnapshot = structuredClone(snapshot);

Expand Down
8 changes: 4 additions & 4 deletions src/hydration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
isStateTreeNode,
tryResolve,
} from 'mobx-state-tree';
import { IValidationResult } from 'mobx-state-tree/dist/internal';
import { IValidationResult, SnapshotOut } from 'mobx-state-tree/dist/internal';
import isObjectLike from '../utils/is-object-like';
import { NearestParent, PathObject, TreeNode, TreeNodeWithValue } from './types';

Expand All @@ -27,13 +27,13 @@ export const validationErrorsParser = (errors: IValidationResult): PathObject[]
};
});

export const removeEmptyItemsRecursively = (obj: any): any => {
export const removeEmptyItemsRecursively = (obj: unknown): unknown => {
if (Array.isArray(obj)) {
return obj
.map((item) => removeEmptyItemsRecursively(item))
.filter((item) => item !== undefined);
} else if (isObjectLike(obj)) {
const newObj: any = {};
const newObj: Record<string, unknown> = {};
for (const key in obj) {
newObj[key] = removeEmptyItemsRecursively(obj[key]);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ export const tryResolveNearestExistingParent = (
return null;
};

export const createDefaultValue = (type: IAnyType): any => {
export const createDefaultValue = <T extends IAnyType>(type: T): SnapshotOut<T> => {
const defaultValue = type.create();
if (isStateTreeNode(defaultValue)) {
return getSnapshot(defaultValue);
Expand Down
10 changes: 5 additions & 5 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import deepObjectOverride from './utils/deep-object-override';
import isDev from './utils/is-dev';

export interface StorageOptions {
setItem: (key: string, value: any) => Promise<void> | void;
getItem: (key: string) => Promise<any | null> | any | null;
setItem: (key: string, value: unknown) => Promise<void> | void;
getItem: (key: string) => Promise<unknown | null> | unknown | null;
removeItem: (key: string) => Promise<void> | void;
}

Expand Down Expand Up @@ -63,7 +63,7 @@ const createPersistentStore = <T extends IAnyModelType>(
* pass it here. The default storage uses `@react-native-async-storage/async-storage` for react-native and `localforage`
* for web.
*
* You can use any storage provider that mplements the same API. ie. `setItem`, `getItem`, `removeItem`.
* You can use unknown storage provider that mplements the same API. ie. `setItem`, `getItem`, `removeItem`.
*
* Note that both `setItem` and `getItem` must handle the serialization and deserialization of data as done by
* localforage. ie. `setItem` must stringify the data before storing and `getItem` must parse the data before returning.
Expand Down Expand Up @@ -100,11 +100,11 @@ const createPersistentStore = <T extends IAnyModelType>(
const PersistentStoreContext = createContext<Instance<T> | null>(null);
const mstStore: Instance<T> = store.create(initStore);

const PersistentStoreProvider: React.FC<PropsWithChildren<{}>> = ({ children }) => {
const PersistentStoreProvider: React.FC<PropsWithChildren<object>> = ({ children }) => {
// Effects will only run on client side.
useAsyncEffect(
async (isMounted) => {
const data = await storage.getItem(storageKey);
const data = await storage.getItem(storageKey) as SnapshotIn<T>;

if (data && isMounted()) {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const getItem = async (key: string) => {
return item ? JSON.parse(item) : null;
};

const setItem = (key: string, value: any) =>
const setItem = (key: string, value: unknown) =>
AsyncStorage.setItem(key, JSON.stringify(value));

const removeItem = (key: string) => AsyncStorage.removeItem(key);
Expand Down
2 changes: 1 addition & 1 deletion src/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import localforage from 'localforage';

const getItem = (key: string) => localforage.getItem(key);

const setItem = (key: string, value: any) => localforage.setItem(key, value);
const setItem = (key: string, value: unknown) => localforage.setItem(key, value);

const removeItem = (key: string) => localforage.removeItem(key);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/create-logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function createLogger(logging: boolean) {
return function logger(...args: any[]) {
return function logger(...args: unknown[]) {
if (logging) {
console.log('[MST-PERSISTENT-STORE]:', ...args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/debounce.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* A function that emits a side effect and does not return anything.
*/
export type Procedure = (...args: any[]) => void;
export type Procedure = (...args: unknown[]) => void;

export type Options = {
isImmediate: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/deep-object-override.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PartialDeep } from '../types/partial-deep';
import isObjectLike from './is-object-like';

export default function deepObjectOverride<T extends Record<string, any>>(
export default function deepObjectOverride<T extends Record<string, unknown>>(
original: T,
overrides?: PartialDeep<T>
): T {
Expand All @@ -22,7 +22,7 @@ export default function deepObjectOverride<T extends Record<string, any>>(
if (Object.keys(overrideValue).length === 0) {
result[key] = overrideValue as T[keyof T];
} else {
result[key] = deepObjectOverride(originalValue, overrideValue);
result[key] = deepObjectOverride(originalValue, overrideValue as PartialDeep<T[keyof T] & Record<string, unknown>>);
}
} else {
result[key] = overrideValue as T[keyof T];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const isDev = () => {
} else {
return false;
}
} catch (e) {
} catch {
return false;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/is-object-like.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const isObjectLike = (value: any): boolean =>
const isObjectLike = (value: unknown): value is Record<string, unknown> =>
value !== null && typeof value === 'object' && !Array.isArray(value);

export default isObjectLike;
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"noEmit": false
},
"exclude": ["node_modules", "dist", "jest.config.js", "**/*.test.ts", "**/*.test.tsx"],
"exclude": ["node_modules", "dist", "eslint.config.js", "jest.config.js", "**/*.test.ts", "**/*.test.tsx"],
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"target": "ES2017",
"noEmit": true,
},
"exclude": ["node_modules", "dist", "jest.config.js"]
"exclude": ["node_modules", "dist", "eslint.config.js", "jest.config.js"]
}
Loading

0 comments on commit d83cf4c

Please sign in to comment.