extra-react-store 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/store.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Emitter } from '@blackglory/structures';
2
2
  export class Store {
3
+ state;
4
+ emitter = new Emitter();
3
5
  constructor(initialState) {
4
- this.emitter = new Emitter();
5
6
  this.state = initialState;
6
7
  }
7
8
  getState() {
package/lib/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAGhD,MAAM,OAAO,KAAK;IAIhB,YAAY,YAAmB;QAFvB,YAAO,GAAG,IAAI,OAAO,EAAoC,CAAA;QAG/D,IAAI,CAAC,KAAK,GAAG,YAAY,CAAA;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,QAAQ,CAAC,QAAe;QACtB,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAA;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAA;IAC7C,CAAC;IAED,SAAS,CAAC,EAA0B;QAClC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;IAC5C,CAAC;CACF"}
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAGhD,MAAM,OAAO,KAAK;IACR,KAAK,CAAO;IACZ,OAAO,GAAG,IAAI,OAAO,EAAoC,CAAA;IAEjE,YAAY,YAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,YAAY,CAAA;IAC3B,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED,QAAQ,CAAC,QAAe;QACtB,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAA;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAA;IAC7C,CAAC;IAED,SAAS,CAAC,EAA0B;QAClC,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;IAC5C,CAAC;CACF"}
package/lib/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { Draft } from 'immer';
3
2
  export type StoreContext<State> = React.Context<IStore<State>>;
4
3
  export interface IStore<State> {
@@ -5,9 +5,11 @@ export function useSelector(context, selector, isEqual = isReferenceEqual) {
5
5
  const store = useContext(context);
6
6
  const [[value], setBox] = useState(() => [selector(store.getState())]);
7
7
  useIsomorphicLayoutEffect(() => {
8
+ let oldValue = value;
8
9
  return store.subscribe(state => {
9
10
  const newValue = selector(state);
10
- if (!isEqual(value, newValue)) {
11
+ if (!isEqual(oldValue, newValue)) {
12
+ oldValue = newValue;
11
13
  setBox([newValue]);
12
14
  }
13
15
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-selector.js","sourceRoot":"","sources":["../src/use-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAE7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,UAAU,WAAW,CACzB,OAA4B,EAC5B,QAAiC,EACjC,UAA2C,gBAAgB;IAE3D,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IACjC,MAAM,CAAC,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ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CAAC,EAAE,CAAC;gBACjC,QAAQ,GAAG,QAAQ,CAAA;gBACnB,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA;YACpB,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;IAE7C,OAAO,KAAK,CAAA;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "extra-react-store",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "files": [
@@ -12,14 +12,14 @@
12
12
  "types": "lib/index.d.ts",
13
13
  "sideEffects": false,
14
14
  "engines": {
15
- "node": ">=16"
15
+ "node": ">=22"
16
16
  },
17
17
  "repository": "git@github.com:BlackGlory/extra-react-store.git",
18
18
  "author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
19
19
  "license": "MIT",
20
20
  "scripts": {
21
21
  "prepare": "ts-patch install -s",
22
- "lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src __tests__",
22
+ "lint": "eslint --quiet src __tests__",
23
23
  "test": "vitest --run",
24
24
  "prepublishOnly": "run-s prepare clean build",
25
25
  "clean": "rimraf lib",
@@ -33,40 +33,41 @@
33
33
  }
34
34
  },
35
35
  "devDependencies": {
36
- "@commitlint/cli": "^17.6.7",
37
- "@commitlint/config-conventional": "^17.6.7",
38
- "@testing-library/react": "^14.0.0",
39
- "@types/react": "^18.2.15",
40
- "@typescript-eslint/eslint-plugin": "^6.14.0",
41
- "@typescript-eslint/parser": "^6.14.0",
42
- "@vitejs/plugin-react": "^4.0.3",
43
- "eslint": "^8.45.0",
44
- "eslint-plugin-react": "^7.33.0",
45
- "eslint-plugin-react-hooks": "^4.6.0",
36
+ "@commitlint/cli": "^19.6.1",
37
+ "@commitlint/config-conventional": "^19.6.0",
38
+ "@eslint/js": "^9.18.0",
39
+ "@testing-library/dom": "^10.4.0",
40
+ "@testing-library/react": "^16.1.0",
41
+ "@types/react": "^19.0.7",
42
+ "@vitejs/plugin-react": "^4.3.4",
43
+ "eslint": "^9.18.0",
44
+ "eslint-plugin-react": "^7.37.4",
45
+ "eslint-plugin-react-hooks": "^5.1.0",
46
46
  "husky": "4",
47
- "immer": "^10.0.2",
48
- "jsdom": "^22.1.0",
47
+ "immer": "^10.1.1",
48
+ "jsdom": "^26.0.0",
49
49
  "npm-run-all": "^4.1.5",
50
- "react": "^18.2.0",
51
- "react-dom": "^18.2.0",
52
- "rimraf": "^5.0.1",
50
+ "react": "^19.0.0",
51
+ "react-dom": "^19.0.0",
52
+ "rimraf": "^6.0.1",
53
53
  "standard-version": "^9.3.2",
54
- "ts-patch": "^3.1.1",
55
- "tslib": "^2.6.2",
56
- "typescript": "5.3.3",
57
- "typescript-transform-paths": "^3.4.6",
58
- "vite": "^4.4.5",
59
- "vite-tsconfig-paths": "^4.2.0",
60
- "vitest": "^0.33.0"
54
+ "ts-patch": "^3.3.0",
55
+ "tslib": "^2.8.1",
56
+ "typescript": "5.7.3",
57
+ "typescript-eslint": "^8.20.0",
58
+ "typescript-transform-paths": "^3.5.3",
59
+ "vite": "^6.0.7",
60
+ "vite-tsconfig-paths": "^5.1.4",
61
+ "vitest": "^2.1.8"
61
62
  },
62
63
  "dependencies": {
63
- "@blackglory/prelude": "^0.3.3",
64
- "@blackglory/structures": "^0.13.4",
65
- "extra-react-hooks": "^0.6.9",
66
- "extra-utils": "^5.4.0"
64
+ "@blackglory/prelude": "^0.4.0",
65
+ "@blackglory/structures": "^0.14.10",
66
+ "extra-react-hooks": "^0.8.0",
67
+ "extra-utils": "^5.17.0"
67
68
  },
68
69
  "peerDependencies": {
69
70
  "immer": "^10.0.2",
70
- "react": "^18"
71
+ "react": "^18 || ^19"
71
72
  }
72
73
  }
@@ -13,10 +13,13 @@ export function useSelector<State, Value>(
13
13
 
14
14
  // `useEffect` will be called too late, resulting in not subscribing in time.
15
15
  useIsomorphicLayoutEffect(() => {
16
+ let oldValue = value
17
+
16
18
  return store.subscribe(state => {
17
19
  const newValue = selector(state)
18
20
 
19
- if (!isEqual(value, newValue)) {
21
+ if (!isEqual(oldValue, newValue)) {
22
+ oldValue = newValue
20
23
  setBox([newValue])
21
24
  }
22
25
  })