Skip to content

Commit

Permalink
TypeScript updates for 0.6
Browse files Browse the repository at this point in the history
Summary:
* Add `isRetained()` to `Snapshot` methods
* Remove `undefined` from `type` in `RecoilStateInfo`

Drive-by cleanup of wording in warning when using released snapshots to change pseudo-function name to avoid starting with `use` so it doesn't look like a hook.

Differential Revision: https://www.internalfb.com/diff/D33593402?entry_point=27

fbshipit-source-id: 5f2b5ba8e895452720ccd895c6a9f55297a4842c
  • Loading branch information
drarmstr authored and facebook-github-bot committed Jan 28, 2022
1 parent d551221 commit 6c23d3b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
- Fix transitive selector refresh for some cases (#1409)
- Fix some corner cases with async selectors and multiple stores (#1568)
- Atom Effects
- Rename option from `effects_UNSTABLE` to just `effects` as the interface is mostly stabilizing (#1520)
- Run atom effects when atoms are initialized from a set during a transaction from `useRecoilTransaction_UNSTABLE()` (#1466)
- Atom effects are cleaned up when initialized by a Snapshot which is released. (#1511, #1532)
- Unsubscribe `onSet()` handlers in atom effects when atoms are cleaned up. (#1509)
Expand All @@ -46,6 +45,7 @@
- Memoize the results of lazy proxies. (#1548)

### Breaking Changes
- Rename atom effects from `effects_UNSTABLE` to just `effects`, as the interface is mostly stabilizing. (#1520)
- Atom effect initialization takes precedence over initialization with `<RecoilRoot initializeState={...} >`. (#1509)
- `useGetRecoilValueInfo_UNSTABLE()` and `Snapshot#getInfo_UNSTABLE()` always report the node `type`. (#1547)

Expand Down
2 changes: 1 addition & 1 deletion packages/recoil/core/Recoil_Snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Recoil Snapshots only last for the duration of the callback they are provided to
const release = snapshot.retain();
try {
await useTheSnapshotAsynchronously(snapshot);
await doSomethingWithSnapshot(snapshot);
} finally {
release();
}
Expand Down
1 change: 1 addition & 0 deletions typescript/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
map(cb: (mutableSnapshot: MutableSnapshot) => void): Snapshot;
asyncMap(cb: (mutableSnapshot: MutableSnapshot) => Promise<void>): Promise<Snapshot>;
retain(): () => void;
isRetained(): boolean;
}

export class MutableSnapshot extends Snapshot {
Expand Down
1 change: 1 addition & 0 deletions typescript/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ useRecoilCallback(({ snapshot, set, reset, refresh, gotoSnapshot, transact_UNSTA

const release = snapshot.retain(); // $ExpectType () => void
release(); // $ExpectType void
snapshot.isRetained(); // $ExpectType boolean

transact_UNSTABLE(({get, set, reset}) => {
const x: number = get(myAtom); // eslint-disable-line @typescript-eslint/no-unused-vars
Expand Down

0 comments on commit 6c23d3b

Please sign in to comment.