File tree Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Expand file tree Collapse file tree 2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -379,6 +379,31 @@ describe(rxState, () => {
379
379
expect ( accumulator ) . toHaveBeenCalled ( ) ;
380
380
} ) ;
381
381
} ) ;
382
+
383
+ describe ( 'asReadOnly' , ( ) => {
384
+ it ( 'should throw error when trying to call set from readOnlystate' , ( ) => {
385
+ const { component } = setupComponent < { count : number } > ( ) ;
386
+
387
+ const readOnlyState = component . state . asReadOnly ( ) ;
388
+
389
+ expect ( ( ) : void => {
390
+ readOnlyState [ 'set' ] (
391
+ 'count' ,
392
+ ( state : { count : number } ) => state . count + 1 ,
393
+ ) ;
394
+ } ) . toThrowError ( 'readOnlyState.set is not a function' ) ;
395
+ } ) ;
396
+
397
+ it ( 'should throw error when trying to call connect from readOnlystate' , ( ) => {
398
+ const { component } = setupComponent < { count : number } > ( ) ;
399
+
400
+ const readOnlyState = component . state . asReadOnly ( ) ;
401
+
402
+ expect ( ( ) : void => {
403
+ readOnlyState [ 'connect' ] ( 'count' , of ( 10 ) ) ;
404
+ } ) . toThrowError ( 'readOnlyState.connect is not a function' ) ;
405
+ } ) ;
406
+ } ) ;
382
407
} ) ;
383
408
384
409
type ITestComponent < State extends object > = {
Original file line number Diff line number Diff line change @@ -12,13 +12,14 @@ export type RxState<T extends object> = Pick<
12
12
| 'signal'
13
13
| 'computed'
14
14
| 'computedFrom'
15
+ | 'asReadOnly'
15
16
> ;
16
17
17
18
export type RxStateSetupFn < State extends object > = (
18
19
rxState : Pick <
19
20
RxState < State > ,
20
21
'connect' | 'set' | 'get' | 'select' | 'setAccumulator'
21
- >
22
+ > ,
22
23
) => void ;
23
24
24
25
/**
@@ -46,7 +47,7 @@ export type RxStateSetupFn<State extends object> = (
46
47
*
47
48
*/
48
49
export function rxState < State extends object > (
49
- setupFn ?: RxStateSetupFn < State >
50
+ setupFn ?: RxStateSetupFn < State > ,
50
51
) : RxState < State > {
51
52
assertInInjectionContext ( rxState ) ;
52
53
@@ -65,6 +66,7 @@ export function rxState<State extends object>(
65
66
computedFrom : legacyState . computedFrom . bind ( legacyState ) ,
66
67
$ : legacyState . $ ,
67
68
setAccumulator : legacyState . setAccumulator . bind ( legacyState ) ,
69
+ asReadOnly : legacyState . asReadOnly . bind ( legacyState ) ,
68
70
} ;
69
71
70
72
setupFn ?.( state ) ;
You can’t perform that action at this time.
0 commit comments