@@ -4,23 +4,21 @@ import { useUpdate } from '../use-update';
44import { type Tools } from '../workloop' ;
55import { useMemo } from '../use-memo' ;
66import { $$scope } from '../scope' ;
7- import { trueFn } from '../utils' ;
87
98type CreateToolsOptions < T > = {
109 next : Value < T > ;
1110 get : ( ) => T ;
1211 set : ( x : T ) => void ;
1312 reset : ( x : T ) => void ;
14- shouldUpdate ?: ( p : T , n : T ) => boolean ;
15- isBatch ?: boolean ;
13+ shouldUpdate : ( p : T , n : T ) => boolean ;
1614} ;
1715
1816function createTools < T > ( options : CreateToolsOptions < T > ) {
19- const { get, set, reset, next, isBatch , shouldUpdate : $shouldUpdate = trueFn } = options ;
17+ const { get, set, reset, next, shouldUpdate : $shouldUpdate } = options ;
2018 const tools = ( ) : Tools => {
2119 const prevValue = get ( ) ;
2220 const newValue = detectIsFunction ( next ) ? next ( prevValue ) : next ;
23- const shouldUpdate = ( ) => isBatch || $shouldUpdate ( prevValue , newValue ) ;
21+ const shouldUpdate = ( ) => $shouldUpdate ( prevValue , newValue ) ;
2422 const setValue = ( ) => set ( newValue ) ;
2523 const resetValue = ( ) => reset ( prevValue ) ;
2624
@@ -43,13 +41,13 @@ function useState<T = unknown>(initialValue: T | (() => T)): [T, (value: Value<T
4341 const setState = useCallback ( ( next : Value < T > ) => {
4442 const $scope = $$scope ( ) ;
4543 const isBatch = $scope . getIsBatch ( ) ;
44+ const isForce = $scope . getIsForce ( ) ;
4645 const getTools = createTools ( {
4746 next,
48- isBatch,
4947 get : ( ) => scope . value ,
5048 set : ( x : T ) => ( scope . value = x ) ,
5149 reset : ( x : T ) => ( scope . value = x ) ,
52- shouldUpdate : ( p : T , n : T ) => ! detectIsEqual ( p , n ) ,
50+ shouldUpdate : ( p : T , n : T ) => isBatch || isForce || ! detectIsEqual ( p , n ) ,
5351 } ) ;
5452
5553 update ( {
@@ -61,4 +59,4 @@ function useState<T = unknown>(initialValue: T | (() => T)): [T, (value: Value<T
6159 return [ scope . value , setState ] ;
6260}
6361
64- export { createTools , useState } ;
62+ export { useState } ;
0 commit comments