Skip to content

Commit 81d9973

Browse files
authored
Module-first steup (#99)
* Module-first steup * update CHANGELOG
1 parent 121e7b9 commit 81d9973

28 files changed

+1678
-5010
lines changed

.codesandbox/ci.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"buildCommand": "compile",
3-
"sandboxes": ["vanilla", "vanilla-typescript-vanilla-ts", "new", "react-typescript-react-ts"],
3+
"sandboxes": [
4+
"vanilla",
5+
"vanilla-typescript-vanilla-ts",
6+
"new",
7+
"react-typescript-react-ts"
8+
],
49
"node": "18"
510
}

.eslintrc.cjs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-env node */
2+
module.exports = {
3+
root: true,
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint'],
6+
extends: [
7+
'eslint:recommended',
8+
'plugin:@typescript-eslint/recommended',
9+
'plugin:import/recommended',
10+
'plugin:import/typescript',
11+
'prettier',
12+
],
13+
ignorePatterns: ['dist/'],
14+
settings: {
15+
'import/resolver': {
16+
typescript: true,
17+
},
18+
},
19+
rules: {
20+
'import/no-unresolved': ['error', { ignore: ['proxy-memoize'] }],
21+
'@typescript-eslint/no-unused-vars': [
22+
'error',
23+
{
24+
args: 'all',
25+
argsIgnorePattern: '^_',
26+
caughtErrors: 'all',
27+
caughtErrorsIgnorePattern: '^_',
28+
destructuredArrayIgnorePattern: '^_',
29+
varsIgnorePattern: '^_',
30+
ignoreRestSiblings: true,
31+
},
32+
],
33+
},
34+
};

.eslintrc.json

-37
This file was deleted.

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/pnpm-lock.yaml
2+
/dist
3+
/README.md
4+
/website/pnpm-lock.yaml

CHANGELOG.md

+57-1
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,58 @@
22

33
## [Unreleased]
44

5+
### Changed
6+
7+
- Module-first steup #99
8+
59
## [2.0.6] - 2024-05-02
10+
611
### Changed
12+
713
- fix: unused selectors #97
814
- refactor: seen WeakSet #98
915

1016
## [2.0.5] - 2024-01-15
17+
1118
### Changed
19+
1220
- fix: no extra calculation with nested memoized selectors #92
1321

1422
## [2.0.4] - 2023-05-06
23+
1524
### Changed
25+
1626
- fix: use target cache for better performance #72
1727

1828
## [2.0.3] - 2023-04-04
29+
1930
### Changed
31+
2032
- build: disable minification #66
2133

2234
## [2.0.2] - 2023-01-31
35+
2336
### Changed
37+
2438
- fix: nested memoized function usage #64
2539

2640
## [2.0.1] - 2023-01-13
41+
2742
### Changed
43+
2844
- fix: abandon cacheKey and avoid re-running touchAffected on cache #60
2945

3046
## [2.0.0] - 2023-01-05
47+
3148
### Changed
49+
3250
- feat: noWeakMap option #53
3351
- breaking: use named exports #56
3452
- feat(deps): update proxy-compare #57
3553
- feat: memoizeWithArgs util #58
54+
3655
### Migration
56+
3757
```js
3858
// old
3959
import memoize, { getUntrackedObject } from 'proxy-memoize';
@@ -42,75 +62,111 @@ import { memoize, getUntracked } from 'proxy-memoize';
4262
```
4363

4464
## [1.2.0] - 2022-08-14
65+
4566
### Changed
46-
- update proxy-compare and re-export replaceNewProxy #48
67+
68+
- update proxy-compare and re-export replaceNewProxy #48
4769

4870
## [1.1.0] - 2022-06-14
71+
4972
### Changed
73+
5074
- refactor with array based queue #41
5175
- fix: nested functions with embedded proxies #46
5276
- update proxy-compare #47
5377

5478
## [1.0.0] - 2022-04-13
79+
5580
### Added
81+
5682
- Initial v1 release (code is not changed from v0.3.8)
5783

5884
## [0.3.8] - 2022-03-18
85+
5986
### Changed
87+
6088
- Update proxy-compare
6189

6290
## [0.3.7] - 2021-09-09
91+
6392
### Changed
93+
6494
- CJS build for Node.js (#32)
6595

6696
## [0.3.6] - 2021-08-13
97+
6798
### Changed
99+
68100
- Fix package.json properly for ESM (#27)
69101

70102
## [0.3.5] - 2021-04-29
103+
71104
### Changed
105+
72106
- Fix package.json for React Native (#25)
73107

74108
## [0.3.4] - 2021-05-15
109+
75110
### Changed
111+
76112
- Update proxy-compare v2.0.0 which only changes interanl API names
77113

78114
## [0.3.3] - 2021-03-23
115+
79116
### Changed
117+
80118
- Fix too much caching (#17)
81119

82120
## [0.3.2] - 2021-01-21
121+
83122
### Changed
123+
84124
- Update proxy-compare v1.1.6 which fixes some edge cases
85125

86126
## [0.3.1] - 2020-12-27
127+
87128
### Changed
129+
88130
- Fix a bug with nested memoized functions (#12)
89131

90132
## [0.3.0] - 2020-12-25
133+
91134
### Added
135+
92136
- Re-export getUntrackedObject from proxy-compare
93137

94138
## [0.2.3] - 2020-11-20
139+
95140
### Changed
141+
96142
- Fix incorrect memoization (#7)
97143

98144
## [0.2.2] - 2020-11-02
145+
99146
### Changed
147+
100148
- Refactor and simplify (#6)
101149

102150
## [0.2.1] - 2020-11-01
151+
103152
### Changed
153+
104154
- Support nested memoize (#5)
105155

106156
## [0.2.0] - 2020-10-31
157+
107158
### Changed
159+
108160
- Support nested memoize (#4) incomplete
109161

110162
## [0.1.1] - 2020-10-26
163+
111164
### Changed
165+
112166
- Fix untrack behavior
113167

114168
## [0.1.0] - 2020-10-25
169+
115170
### Added
171+
116172
- Initial release

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Contributions are welcome.
1919

2020
Immutability is pivotal in more than a few frameworks, like React and Redux. It enables simple-yet-efficient change detection in large nested data structures.
2121

22-
JavaScript is a mutable language by default. Libraries like [immer](https://github.com/immerjs/immer) simplify _updating_ immutable data strucutres.
22+
JavaScript is a mutable language by default. Libraries like [immer](https://github.com/immerjs/immer) simplify *updating* immutable data strucutres.
2323

24-
This library helps _deriving data_ from immutable structures (AKA, selectors), efficiantly caching results for faster performance.
24+
This library helps *deriving data* from immutable structures (AKA, selectors), efficiantly caching results for faster performance.
2525

2626
This library utilizes Proxy and WeakMap, and provides memoization.
2727
The memoized function will re-evaluate the original function

docs/react-redux/useProxySelector.md

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# useProxySelector
2+
23
This creates a `useProxySelector` hook which can be used to create a typed `useSelector` hook powered by `proxy-memoize`. By defining this hook in your application code, you can ensure that the `state` object reflects your redux state object.
34

45
## The Hook
6+
57
```ts
6-
import { memoize } from "proxy-memoize";
7-
import { useCallback } from "react";
8-
import { useSelector } from "react-redux";
8+
import { memoize } from 'proxy-memoize';
9+
import { useCallback } from 'react';
10+
import { useSelector } from 'react-redux';
911

1012
// import your react-redux RootState type
11-
import type { RootState } from "./path/to/root/state/declaration";
13+
import type { RootState } from './path/to/root/state/declaration';
1214

1315
const createProxySelectorHook = <TState extends object = any>() => {
1416
const useProxySelector = <TReturnType>(
1517
fn: (state: TState) => TReturnType,
16-
deps?: any[]
18+
deps?: any[],
1719
): TReturnType => {
1820
// eslint-disable-next-line react-hooks/exhaustive-deps
1921
return useSelector(useCallback(memoize(fn), deps));
@@ -26,15 +28,19 @@ export const useProxySelector = createProxySelectorHook<RootState>();
2628
```
2729

2830
## Usage in Code
31+
2932
```tsx
3033
interface Props {
3134
value: string;
3235
}
3336

34-
const MyComponent:React.FC<Props> = ({ value }) => {
35-
const result = useProxySelector((state) => {
36-
return `${value}-modified`
37-
}, [value]);
38-
return (<div>{result}</div>);
39-
}
37+
const MyComponent: React.FC<Props> = ({ value }) => {
38+
const result = useProxySelector(
39+
(state) => {
40+
return `${value}-modified`;
41+
},
42+
[value],
43+
);
44+
return <div>{result}</div>;
45+
};
4046
```

0 commit comments

Comments
 (0)