@@ -29,8 +29,14 @@ describe('createAtomStore', () => {
29
29
arr : INITIAL_ARR ,
30
30
} ;
31
31
32
- const { useMyTestStoreStore, MyTestStoreProvider, useMyTestStoreValue } =
33
- createAtomStore ( initialTestStoreValue , { name : 'myTestStore' as const } ) ;
32
+ const {
33
+ myTestStoreStore,
34
+ useMyTestStoreStore,
35
+ MyTestStoreProvider,
36
+ useMyTestStoreValue,
37
+ } = createAtomStore ( initialTestStoreValue , {
38
+ name : 'myTestStore' as const ,
39
+ } ) ;
34
40
35
41
let numRenderCount = 0 ;
36
42
const NumRenderer = ( ) => {
@@ -121,6 +127,21 @@ describe('createAtomStore', () => {
121
127
) ;
122
128
} ;
123
129
130
+ let arrNumRenderWithDepsAndAtomCount = 0 ;
131
+ const ArrNumRendererWithDepsAndAtom = ( ) => {
132
+ arrNumRenderWithDepsAndAtomCount += 1 ;
133
+ const store = useMyTestStoreStore ( ) ;
134
+ const numAtom = myTestStoreStore . atom . num ;
135
+ const num = store . useAtomValue ( numAtom ) ;
136
+ const arrAtom = myTestStoreStore . atom . arr ;
137
+ const arrNum = store . useAtomValue ( arrAtom , ( v ) => v [ num ] , [ num ] ) ;
138
+ return (
139
+ < div >
140
+ < div > arrNumWithDepsAndAtom: { arrNum } </ div >
141
+ </ div >
142
+ ) ;
143
+ } ;
144
+
124
145
const BadSelectorRenderer = ( ) => {
125
146
const arr0 = useMyTestStoreStore ( ) . useArrValue ( ( v ) => v [ 0 ] ) ;
126
147
return < div > { arr0 } </ div > ;
@@ -177,6 +198,7 @@ describe('createAtomStore', () => {
177
198
< ArrNumRenderer />
178
199
< ArrNumRendererWithOneHook />
179
200
< ArrNumRendererWithDeps />
201
+ < ArrNumRendererWithDepsAndAtom />
180
202
< Buttons />
181
203
</ MyTestStoreProvider >
182
204
) ;
@@ -190,6 +212,7 @@ describe('createAtomStore', () => {
190
212
expect ( arrNumRenderCount ) . toBe ( 2 ) ;
191
213
expect ( arrNumRenderCountWithOneHook ) . toBe ( 2 ) ;
192
214
expect ( arrNumRenderWithDepsCount ) . toBe ( 2 ) ;
215
+ expect ( arrNumRenderWithDepsAndAtomCount ) . toBe ( 2 ) ;
193
216
expect ( getByText ( 'arrNum: alice' ) ) . toBeInTheDocument ( ) ;
194
217
expect ( getByText ( 'arrNumWithDeps: alice' ) ) . toBeInTheDocument ( ) ;
195
218
@@ -202,6 +225,7 @@ describe('createAtomStore', () => {
202
225
expect ( arrNumRenderCount ) . toBe ( 5 ) ;
203
226
expect ( arrNumRenderCountWithOneHook ) . toBe ( 5 ) ;
204
227
expect ( arrNumRenderWithDepsCount ) . toBe ( 5 ) ;
228
+ expect ( arrNumRenderWithDepsAndAtomCount ) . toBe ( 5 ) ;
205
229
expect ( getByText ( 'arrNum: bob' ) ) . toBeInTheDocument ( ) ;
206
230
expect ( getByText ( 'arrNumWithDeps: bob' ) ) . toBeInTheDocument ( ) ;
207
231
@@ -214,6 +238,7 @@ describe('createAtomStore', () => {
214
238
expect ( arrNumRenderCount ) . toBe ( 5 ) ;
215
239
expect ( arrNumRenderCountWithOneHook ) . toBe ( 5 ) ;
216
240
expect ( arrNumRenderWithDepsCount ) . toBe ( 5 ) ;
241
+ expect ( arrNumRenderWithDepsAndAtomCount ) . toBe ( 5 ) ;
217
242
expect ( getByText ( 'arrNum: bob' ) ) . toBeInTheDocument ( ) ;
218
243
expect ( getByText ( 'arrNumWithDeps: bob' ) ) . toBeInTheDocument ( ) ;
219
244
@@ -226,6 +251,7 @@ describe('createAtomStore', () => {
226
251
expect ( arrNumRenderCount ) . toBe ( 5 ) ;
227
252
expect ( arrNumRenderCountWithOneHook ) . toBe ( 5 ) ;
228
253
expect ( arrNumRenderWithDepsCount ) . toBe ( 5 ) ;
254
+ expect ( arrNumRenderWithDepsAndAtomCount ) . toBe ( 5 ) ;
229
255
expect ( getByText ( 'arrNum: bob' ) ) . toBeInTheDocument ( ) ;
230
256
expect ( getByText ( 'arrNumWithDeps: bob' ) ) . toBeInTheDocument ( ) ;
231
257
@@ -238,6 +264,7 @@ describe('createAtomStore', () => {
238
264
expect ( arrNumRenderCount ) . toBe ( 8 ) ;
239
265
expect ( arrNumRenderCountWithOneHook ) . toBe ( 8 ) ;
240
266
expect ( arrNumRenderWithDepsCount ) . toBe ( 8 ) ;
267
+ expect ( arrNumRenderWithDepsAndAtomCount ) . toBe ( 8 ) ;
241
268
expect ( getByText ( 'arrNum: ava' ) ) . toBeInTheDocument ( ) ;
242
269
expect ( getByText ( 'arrNumWithDeps: ava' ) ) . toBeInTheDocument ( ) ;
243
270
} ) ;
0 commit comments