@@ -29,10 +29,8 @@ describe('createAtomStore', () => {
2929 arr : INITIAL_ARR ,
3030 } ;
3131
32- const { useMyTestStoreStore, MyTestStoreProvider } = createAtomStore (
33- initialTestStoreValue ,
34- { name : 'myTestStore' as const }
35- ) ;
32+ const { useMyTestStoreStore, MyTestStoreProvider, useMyTestStoreValue } =
33+ createAtomStore ( initialTestStoreValue , { name : 'myTestStore' as const } ) ;
3634
3735 let numRenderCount = 0 ;
3836 const NumRenderer = ( ) => {
@@ -92,6 +90,24 @@ describe('createAtomStore', () => {
9290 ) ;
9391 } ;
9492
93+ let arrNumRenderCountWithOneHook = 0 ;
94+ const ArrNumRendererWithOneHook = ( ) => {
95+ arrNumRenderCountWithOneHook += 1 ;
96+ const num = useMyTestStoreValue ( 'num' ) ;
97+ const arrNum = useMyTestStoreValue (
98+ 'arr' ,
99+ {
100+ selector : ( v ) => v [ num ] ,
101+ } ,
102+ [ num ]
103+ ) ;
104+ return (
105+ < div >
106+ < div > arrNumWithOneHook: { arrNum } </ div >
107+ </ div >
108+ ) ;
109+ } ;
110+
95111 let arrNumRenderWithDepsCount = 0 ;
96112 const ArrNumRendererWithDeps = ( ) => {
97113 arrNumRenderWithDepsCount += 1 ;
@@ -110,6 +126,11 @@ describe('createAtomStore', () => {
110126 return < div > { arr0 } </ div > ;
111127 } ;
112128
129+ const BadSelectorRenderer2 = ( ) => {
130+ const arr0 = useMyTestStoreValue ( 'arr' , { selector : ( v ) => v [ 0 ] } ) ;
131+ return < div > { arr0 } </ div > ;
132+ } ;
133+
113134 const Buttons = ( ) => {
114135 const store = useMyTestStoreStore ( ) ;
115136 return (
@@ -154,6 +175,7 @@ describe('createAtomStore', () => {
154175 < Arr0Renderer />
155176 < Arr1Renderer />
156177 < ArrNumRenderer />
178+ < ArrNumRendererWithOneHook />
157179 < ArrNumRendererWithDeps />
158180 < Buttons />
159181 </ MyTestStoreProvider >
@@ -166,6 +188,7 @@ describe('createAtomStore', () => {
166188 expect ( arr0RenderCount ) . toBe ( 2 ) ;
167189 expect ( arr1RenderCount ) . toBe ( 2 ) ;
168190 expect ( arrNumRenderCount ) . toBe ( 2 ) ;
191+ expect ( arrNumRenderCountWithOneHook ) . toBe ( 2 ) ;
169192 expect ( arrNumRenderWithDepsCount ) . toBe ( 2 ) ;
170193 expect ( getByText ( 'arrNum: alice' ) ) . toBeInTheDocument ( ) ;
171194 expect ( getByText ( 'arrNumWithDeps: alice' ) ) . toBeInTheDocument ( ) ;
@@ -177,6 +200,7 @@ describe('createAtomStore', () => {
177200 expect ( arr0RenderCount ) . toBe ( 2 ) ;
178201 expect ( arr1RenderCount ) . toBe ( 2 ) ;
179202 expect ( arrNumRenderCount ) . toBe ( 5 ) ;
203+ expect ( arrNumRenderCountWithOneHook ) . toBe ( 5 ) ;
180204 expect ( arrNumRenderWithDepsCount ) . toBe ( 5 ) ;
181205 expect ( getByText ( 'arrNum: bob' ) ) . toBeInTheDocument ( ) ;
182206 expect ( getByText ( 'arrNumWithDeps: bob' ) ) . toBeInTheDocument ( ) ;
@@ -188,6 +212,7 @@ describe('createAtomStore', () => {
188212 expect ( arr0RenderCount ) . toBe ( 2 ) ;
189213 expect ( arr1RenderCount ) . toBe ( 2 ) ;
190214 expect ( arrNumRenderCount ) . toBe ( 5 ) ;
215+ expect ( arrNumRenderCountWithOneHook ) . toBe ( 5 ) ;
191216 expect ( arrNumRenderWithDepsCount ) . toBe ( 5 ) ;
192217 expect ( getByText ( 'arrNum: bob' ) ) . toBeInTheDocument ( ) ;
193218 expect ( getByText ( 'arrNumWithDeps: bob' ) ) . toBeInTheDocument ( ) ;
@@ -199,6 +224,7 @@ describe('createAtomStore', () => {
199224 expect ( arr0RenderCount ) . toBe ( 2 ) ;
200225 expect ( arr1RenderCount ) . toBe ( 2 ) ;
201226 expect ( arrNumRenderCount ) . toBe ( 5 ) ;
227+ expect ( arrNumRenderCountWithOneHook ) . toBe ( 5 ) ;
202228 expect ( arrNumRenderWithDepsCount ) . toBe ( 5 ) ;
203229 expect ( getByText ( 'arrNum: bob' ) ) . toBeInTheDocument ( ) ;
204230 expect ( getByText ( 'arrNumWithDeps: bob' ) ) . toBeInTheDocument ( ) ;
@@ -210,6 +236,7 @@ describe('createAtomStore', () => {
210236 expect ( arr0RenderCount ) . toBe ( 3 ) ;
211237 expect ( arr1RenderCount ) . toBe ( 2 ) ;
212238 expect ( arrNumRenderCount ) . toBe ( 8 ) ;
239+ expect ( arrNumRenderCountWithOneHook ) . toBe ( 8 ) ;
213240 expect ( arrNumRenderWithDepsCount ) . toBe ( 8 ) ;
214241 expect ( getByText ( 'arrNum: ava' ) ) . toBeInTheDocument ( ) ;
215242 expect ( getByText ( 'arrNumWithDeps: ava' ) ) . toBeInTheDocument ( ) ;
@@ -224,6 +251,16 @@ describe('createAtomStore', () => {
224251 )
225252 ) . toThrow ( ) ;
226253 } ) ;
254+
255+ it ( 'Throw error is user does memoize selector 2' , ( ) => {
256+ expect ( ( ) =>
257+ render (
258+ < MyTestStoreProvider >
259+ < BadSelectorRenderer2 />
260+ </ MyTestStoreProvider >
261+ )
262+ ) . toThrow ( ) ;
263+ } ) ;
227264 } ) ;
228265
229266 describe ( 'single provider' , ( ) => {
0 commit comments