Skip to content

Commit ae315b3

Browse files
authored
add changelog (#285)
1 parent 4c48d7c commit ae315b3

File tree

1 file changed

+197
-0
lines changed

1 file changed

+197
-0
lines changed

CHANGELOG.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
## 0.10.3 (2022-09-09)
2+
3+
- fix: avoid errors on unmounted Suspense components
4+
5+
## 0.10.2 (2022-09-09)
6+
7+
- fix: pipeState also enhanced as a React element (#282)
8+
9+
## 0.10.1 (2022-09-09)
10+
11+
- fix: re-export types correctly from @rx-state/core
12+
13+
### utils
14+
15+
- chore: rename `selfDependant` to `selfDependent` (#272)
16+
17+
## 0.10.0 (2022-09-09)
18+
19+
- StateObservables as JSX Elements.
20+
21+
StateObservables are now also JSX Elements, which lets you use them directly as children of other components.
22+
23+
```tsx
24+
const count$ = state(interval(1000), 0)
25+
26+
const App = () => {
27+
const count = useStateObservable(count$)
28+
29+
return <div>{count}</div>
30+
}
31+
32+
// Becomes
33+
34+
const App = () => {
35+
return <div>{count$}</div>
36+
}
37+
```
38+
39+
- `.pipeState()`, `withDefault()`
40+
41+
StateObservables now have a shorthand method `.pipeState(...args)` which works as RxJS `.pipe(`, but it wraps the result into a new state.
42+
43+
```ts
44+
const newState$ = state(
45+
parent$.pipe(
46+
map(...)
47+
)
48+
)
49+
50+
// Becomes
51+
const newState$ = parent$.pipeState(
52+
map(...)
53+
)
54+
```
55+
56+
`withDefault(value)` is an operator that creates a DefaultedStateObservable. It can be used at the end of `pipeState` to set the default value for that one.
57+
58+
```ts
59+
const newState$ = state(
60+
parent$.pipe(
61+
map(...)
62+
),
63+
"defaultVal"
64+
)
65+
66+
// Becomes
67+
const newState$ = parent$.pipeState(
68+
map(...),
69+
withDefault("defaultVal")
70+
)
71+
```
72+
73+
- Add additional argument on factory observables to prevent using them in incompatible HOF.
74+
75+
Previously factory functions had the same signature that was passed into the function. You can use them in higher-order-functions and Typescript will think it's valid:
76+
77+
```ts
78+
const user$ = state((id: string) => ...);
79+
80+
const selectedUser$ = state(
81+
selectedId$.pipe(
82+
switchMap(user$)
83+
)
84+
);
85+
```
86+
87+
This is problematic because `switchMap` also passes in the number of elements emitted so far as the second argument, and the parametric state will then understand each call as a new instance.
88+
89+
Now `user$` will have a typescript signature that will prevent it from being used into places that give more parameters than it has, so Typescript will flag this as an error.
90+
91+
- `sinkSuspense()`, `liftSuspense()`
92+
93+
These two new operators help deal with SUSPENSE values on the streams, which is useful when the meaning of SUSPENSE is that everything needs to be reset.
94+
95+
`sinkSuspense()` is an operator that when it receives a SUSPENSE, it will throw it as an error down the stream, which resets all of the observables down below. It will then hold the subscription to the upstream, waiting for a resubscription to happen immediately. If it doesn't happen, then it will unsubscribe from upstream.
96+
97+
`liftSuspense()` is an operator that when it receives SUSPENSE as an error, it will immediately resubscribe to its upstream, and emit SUSPENSE as a value.
98+
99+
This allows to avoid dealing with SUSPENSE on the streams that are in-between the one that generates SUSPENSE and the one that needs to receive it.
100+
101+
```ts
102+
const account$ = accountSwitch$.pipe(switchMapSuspended((v) => fetchAccount(v)))
103+
104+
const posts$ = account$.pipe(
105+
switchMap((v) => (v === SUSPENSE ? of(SUSPENSE) : fetchPosts(v))),
106+
)
107+
108+
/// with sinkSuspense
109+
const account$ = accountSwitch$.pipe(
110+
switchMapSuspended((v) => fetchAccount(v)),
111+
sinkSuspense(),
112+
)
113+
114+
const posts$ = account$.pipe(switchMap((v) => fetchPosts(v)))
115+
```
116+
117+
`useStateObservable` is already fitted with `liftSuspense()`, so there's no need to call it on the StateObservables that are to be used in components.
118+
119+
It's very important to remember that `sinkSuspense` is throwing SUSPENSE values as errors, which means that subscriptions will get closed, in ways that are not always obvious. In most of the cases, it can be solved by using `liftSuspense()`, dealing with that value, and calling `sinkSuspense()` again. Use at your own risk.
120+
121+
### Fixes
122+
123+
- Fix observable of promises triggering suspense.
124+
- Fix observables emitting synchronous completes triggering NoSubscribersError on Subscribe
125+
126+
## 0.9.8 (2022-06-24)
127+
128+
- Fix asynchronous errors on Subscribe not getting caught on ErrorBoundaries.
129+
130+
## 0.9.7 (2022-06-14)
131+
132+
- Fix Subscribe error on immediate unmount when running in React18 StrictMode
133+
134+
## 0.9.6 (2022-04-29)
135+
136+
- RemoveSubscribe
137+
138+
New component that prevents its children from using a parent `<Subscribe>` to manage their subscriptions.
139+
140+
- improve SUSPENSE types
141+
142+
## 0.9.5 (2022-04-11)
143+
144+
- upgrade dependencies (React 18)
145+
146+
## 0.9.4 (2022-04-04)
147+
148+
- utils: `toKeySet()`
149+
150+
Operator that turns an `Observable<KeyChanges<K>>` into an `Observable<Set<K>>`
151+
152+
- fix useStateObservable on StateObservables that emit synchronously without default value.
153+
- fix partitionByKey not emitting synchronously when a new group came in.
154+
155+
## 0.9.3 (2022-03-30)
156+
157+
- utils: Improve performance of `partitionByKey` with a big number of elements (#232)
158+
159+
BREAKING CHANGE: partitionByKey's key stream now returns deltas `Observable<KeyChanges<K>>` instead of list of keys `Observable<K[]>`. Shouldn't have an impact if the stream was used directly into `combineKeys`.
160+
161+
- fix Subscribe running in react18 StrictMode (#249)
162+
163+
## 0.9.2 (2022-03-29)
164+
165+
- fix React Native build
166+
167+
## 0.9.1 (2022-03-27)
168+
169+
- fix types for DefaultedStateObservable
170+
- fix compile error on Next.js 12
171+
172+
## 0.9.0 (2022-03-20)
173+
174+
- `state()`, `useStateObservable()`
175+
176+
There's a different way of creating and consuming observables now.
177+
178+
Instead of calling `bind` which returns a hook and a shared observable, `state()` just returns the shared observable. This can be consumed in the components by using the hook `useStateObservable()`.
179+
180+
```tsx
181+
const [useUser, user$] = bind(fetchUser());
182+
183+
const App = () => {
184+
const user = useUser();
185+
186+
...
187+
}
188+
189+
// Becomes
190+
const user$ = state(fetchUser());
191+
192+
const App = () => {
193+
const user = useStateObservable(user$);
194+
195+
...
196+
}
197+
```

0 commit comments

Comments
 (0)