You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -20,3 +24,207 @@ Version 20 has the minimum version requirements:
20
24
- RxJS version ^6.5.x || ^7.5.0
21
25
22
26
## Breaking changes
27
+
28
+
### Signals
29
+
30
+
The internal `STATE_SOURCE` is no longer represented as a single `WritableSignal` holding the entire state object. Instead, each top-level state property becomes its own `WritableSignal` or remains as-is if a `WritableSignal` is provided as a state property.
31
+
32
+
BEFORE:
33
+
34
+
1. The initial state object reference is preserved:
35
+
36
+
```ts
37
+
const initialState = { ngrx: 'rocks' };
38
+
39
+
// signalState:
40
+
const state =signalState(initialState);
41
+
state() ===initialState; // true
42
+
43
+
// withState:
44
+
const Store =signalStore(withState(initialState));
45
+
const store =newStore();
46
+
getState(store) ===initialState; // true
47
+
```
48
+
49
+
2. Top-level `WritableSignal`s are wrapped with `Signal`s:
50
+
51
+
```ts
52
+
// signalState:
53
+
const state =signalState({ ngrx: signal('rocks') });
54
+
state.ngrx// type: Signal<WritableSignal<string>>
55
+
56
+
// withState:
57
+
const Store =signalStore(withState({ ngrx: signal('rocks') }));
58
+
const store =newStore();
59
+
store.ngrx// type: Signal<WritableSignal<string>>
60
+
```
61
+
62
+
3. Root state properties can be added dynamically:
63
+
64
+
```ts
65
+
// signalState:
66
+
const state =signalState<Record<string, string>>({});
1. The initial state object reference is not preserved:
87
+
88
+
```ts
89
+
const initialState = { ngrx: 'rocks' };
90
+
91
+
// signalState:
92
+
const state =signalState(initialState);
93
+
state() ===initialState; // false
94
+
95
+
// withState:
96
+
const Store =signalStore(withState(initialState));
97
+
const store =newStore();
98
+
getState(store) ===initialState; // false
99
+
```
100
+
101
+
2. Top-level `WritableSignal`s are not wrapped with `Signal`s:
102
+
103
+
```ts
104
+
// signalState:
105
+
const state =signalState({ ngrx: signal('rocks') });
106
+
state.ngrx// type: Signal<string>
107
+
108
+
// withState:
109
+
const Store =signalStore(withState({ ngrx: signal('rocks') }));
110
+
const store =newStore();
111
+
store.ngrx// type: Signal<string>
112
+
```
113
+
114
+
3. Root state properties can not be added dynamically:
115
+
116
+
```ts
117
+
// signalState:
118
+
const state =signalState<Record<string, string>>({});
119
+
console.log(state()); // {}
120
+
121
+
patchState(state, { ngrx: 'rocks' });
122
+
console.log(state()); // {}
123
+
124
+
// withState:
125
+
const Store =signalStore(
126
+
{ protectedState: false },
127
+
withState<Record<string, string>>({})
128
+
);
129
+
const store =newStore();
130
+
console.log(getState(store)); // {}
131
+
132
+
patchState(store, { ngrx: 'rocks' });
133
+
console.log(getState(store)); // {}
134
+
```
135
+
136
+
### Entity
137
+
138
+
#### `getInitialState` is type-safe
139
+
140
+
`getInitialState` is now type-safe, meaning that the initial state must match the entity state type. This change ensures that the initial state is correctly typed and prevents additional properties from being added to the state.
0 commit comments