Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ludvigalden committed Jan 10, 2022
1 parent f9e8d71 commit eb1e201
Show file tree
Hide file tree
Showing 23 changed files with 257 additions and 335 deletions.
11 changes: 2 additions & 9 deletions .eslintrc.js
Expand Up @@ -4,13 +4,10 @@ module.exports = {
"plugin:prettier/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"prettier/babel",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"prettier/@typescript-eslint",
"plugin:react/recommended",
"prettier/react",
],
plugins: ["babel", "import", "prettier", "react", "unused-imports"],
env: {
Expand Down Expand Up @@ -123,7 +120,7 @@ module.exports = {
2,
{
"newlines-between": "always",
groups: ["external", "internal", ["parent", "sibling"], "index"],
groups: ["external", "unknown", "internal", ["parent", "sibling"], "index"],
alphabetize: {
order: "asc",
caseInsensitive: true,
Expand All @@ -150,7 +147,7 @@ module.exports = {
"prefer-object-spread": 1,
"no-duplicate-imports": 2,
"no-return-await": 2,
"no-invalid-this": 1,
"no-invalid-this": 0,
"no-invalid-template-strings": 0,
"no-arg": 0,
"no-confusing-arrow": 0,
Expand Down Expand Up @@ -180,10 +177,6 @@ module.exports = {
"react/jsx-uses-react": "warn",
"react/jsx-uses-vars": "warn",
"react/no-danger-with-children": "warn",
// Disabled because of undesirable warnings
// See https://github.com/facebook/create-react-app/issues/5204 for
// blockers until its re-enabled
// 'react/no-deprecated': 'warn',
"react/no-direct-mutation-state": "warn",
"react/no-is-mounted": "warn",
"react/no-typos": "error",
Expand Down
2 changes: 1 addition & 1 deletion .huskyrc.js
@@ -1,5 +1,5 @@
module.exports = {
hooks: {
"pre-commit": "lint-staged -c ./.lintstagedrc.js && npm run build && npm run test"
"pre-commit": "lint-staged -c ./.lintstagedrc.js"
},
};
2 changes: 1 addition & 1 deletion examples/user-profile/user-profile.tsx
@@ -1,8 +1,8 @@
import React from "react";

import { UserState } from "./user-state";
import UserProfileAvatar from "./user-profile.avatar";
import UserProfileName from "./user-profile.name";
import { UserState } from "./user-state";

export default function UserProfile(props: UserProfileProps) {
const state = React.useMemo(() => new UserState(props.id), [props.id]);
Expand Down
41 changes: 21 additions & 20 deletions package.json
Expand Up @@ -38,35 +38,36 @@
},
"dependencies": {
"lodash": "*",
"use-cleared-memo": "1.2.0"
"use-cleared-memo": "1.2.0",
"use-safe-force-update": "1.0.1"
},
"peerDependencies": {
"react": ">=16.8.0"
},
"devDependencies": {
"@types/lodash": "^4.14.161",
"@types/lodash": "^4.14.178",
"@types/react": "^16.9.23",
"@typescript-eslint/eslint-plugin": "4.2.0",
"@typescript-eslint/parser": "4.2.0",
"@typescript-eslint/eslint-plugin": "5.9.0",
"@typescript-eslint/parser": "5.9.0",
"babel-eslint": "10.1.0",
"babel-jest": "^25.1.0",
"eslint": "7.9.0",
"eslint-config-prettier": "6.12.0",
"eslint-import-resolver-typescript": "2.3.0",
"babel-jest": "^27.4.6",
"eslint": "8.6.0",
"eslint-config-prettier": "8.3.0",
"eslint-import-resolver-typescript": "2.5.0",
"eslint-loader": "4.0.2",
"eslint-plugin-babel": "5.3.1",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-prettier": "3.1.4",
"eslint-plugin-react": "7.21.2",
"eslint-plugin-unused-imports": "^0.1.3",
"eslint-plugin-import": "2.25.4",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-react": "7.28.0",
"eslint-plugin-unused-imports": "^2.0.0",
"got": "^10.6.0",
"husky": "^4.2.3",
"lint-staged": "10.4.0",
"np": "6.5.0",
"prettier": "2.1.2",
"react": "^16.8.0",
"ts-node": "9.0.0",
"tsdx": "0.14.0",
"typescript": "4.0.3"
"lint-staged": "12.1.7",
"np": "7.6.0",
"prettier": "2.5.1",
"react": "^17.0.2",
"ts-node": "10.4.0",
"tsdx": "0.14.1",
"typescript": "4.5.4"
}
}
}
5 changes: 3 additions & 2 deletions src/abon-array.ts
@@ -1,10 +1,11 @@
import isEqual from "lodash/isEqual";
import React from "react";
import { useClearedMemo } from "use-cleared-memo";
import { useSafeForceUpdate } from "use-safe-force-update";

import { Notifier } from "./notifier";
import { ChangeListener, UnsubscribeFn, ValueHandler } from "./types";
import { useClearedValueSubscription, useMountedForceUpdate, validateListener } from "./utils";
import { useClearedValueSubscription, validateListener } from "./utils";

/** Subscribe to and update a normal array. */
export class AbonArray<T> extends Array<T> {
Expand Down Expand Up @@ -137,7 +138,7 @@ export class AbonArray<T> extends Array<T> {
}

use() {
const forceUpdate = useMountedForceUpdate();
const forceUpdate = useSafeForceUpdate();

useClearedValueSubscription(
this.current,
Expand Down
5 changes: 3 additions & 2 deletions src/abon-async.ts
@@ -1,11 +1,12 @@
import isEqual from "lodash/isEqual";
import React from "react";
import { useClearedMemo } from "use-cleared-memo";
import { useSafeForceUpdate } from "use-safe-force-update";

import { Abon } from "./abon";
import { Notifier } from "./notifier";
import { ChangeListener, UnsubscribeFn, ValueHandler } from "./types";
import { useClearedValueSubscription, useMountedForceUpdate, validateListener } from "./utils";
import { useClearedValueSubscription, validateListener } from "./utils";

/** Subscribe to, retrieve, and asynchronously update a value, where an action to set a value can be interrupted.
* `AbonAsync` is not intended to be used by itself, but rather to be extended and implementing the `set` method. */
Expand Down Expand Up @@ -109,7 +110,7 @@ export class AbonAsync<T> implements Omit<Abon<T>, "set" | "use"> {
}

use() {
const forceUpdate = useMountedForceUpdate();
const forceUpdate = useSafeForceUpdate();

useClearedValueSubscription(
this.current,
Expand Down
14 changes: 7 additions & 7 deletions src/abon-deep.ts
Expand Up @@ -3,7 +3,7 @@ import merge from "lodash/merge";
import set from "lodash/set";
import React from "react";

import { NotifierDeep } from "./notifier";
import { NotifierDeep } from "./notifier-deep";
import { ReadonlyAbonDeep } from "./readonly-abon-deep";

/** Subscribe to, retrieve, and set deeply nested values. */
Expand Down Expand Up @@ -40,30 +40,30 @@ export class AbonDeep<T extends object> extends ReadonlyAbonDeep<T> {
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4]
K5 extends keyof T[K1][K2][K3][K4],
>(_1: K1, _2: K2, _3: K3, _4: K4, _5: K5, value: T[K1][K2][K3][K4][K5]): this;
set<
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4]
K5 extends keyof T[K1][K2][K3][K4],
>(keys: [K1, K2, K3, K4, K5], value: T[K1][K2][K3][K4][K5]): this;
set<
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5]
K6 extends keyof T[K1][K2][K3][K4][K5],
>(_1: K1, _2: K2, _3: K3, _4: K4, _5: K5, _6: K6, value: T[K1][K2][K3][K4][K5][K6]): this;
set<
K1 extends keyof T,
K2 extends keyof T[K1],
K3 extends keyof T[K1][K2],
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5]
K6 extends keyof T[K1][K2][K3][K4][K5],
>(keys: [K1, K2, K3, K4, K5, K6], value: T[K1][K2][K3][K4][K5][K6]): this;
set<
K1 extends keyof T,
Expand All @@ -72,7 +72,7 @@ export class AbonDeep<T extends object> extends ReadonlyAbonDeep<T> {
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5],
K7 extends keyof T[K1][K2][K3][K4][K5][K6]
K7 extends keyof T[K1][K2][K3][K4][K5][K6],
>(_1: K1, _2: K2, _3: K3, _4: K4, _5: K5, _6: K6, _7: K6, value: T[K1][K2][K3][K4][K5][K6][K7]): this;
set<
K1 extends keyof T,
Expand All @@ -81,7 +81,7 @@ export class AbonDeep<T extends object> extends ReadonlyAbonDeep<T> {
K4 extends keyof T[K1][K2][K3],
K5 extends keyof T[K1][K2][K3][K4],
K6 extends keyof T[K1][K2][K3][K4][K5],
K7 extends keyof T[K1][K2][K3][K4][K5][K6]
K7 extends keyof T[K1][K2][K3][K4][K5][K6],
>(keys: [K1, K2, K3, K4, K5, K6, K7], value: T[K1][K2][K3][K4][K5][K6][K7]): this;
set(...args: any[]) {
const { keys, value } = AbonDeep.parseKeyValueArgs(args);
Expand Down

0 comments on commit eb1e201

Please sign in to comment.