Skip to content

Commit

Permalink
getInfo() always reports atom/selector type. (#1547)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #1547

When `useGetRecoilValueInfo_UNSTABLE()` or `Snapshot#getInfo_UNSTABLE()` callbacks were originally implemented the atom and selector internal node interface was more abstract.  Now there is an explicit `'atom' | 'selector'` type which we can use to always report the type of any registered node.

Reviewed By: habond

Differential Revision: D33559658

fbshipit-source-id: 096b04f0211e58604c949c61d51d2b0257f05e87
  • Loading branch information
drarmstr authored and facebook-github-bot committed Jan 20, 2022
1 parent 0cc4b92 commit 69acb21
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

### Breaking Changes
- Atom effect initialization takes precedence over initialization with `<RecoilRoot initializeState={...} >`. (#1509)
- `useGetRecoilValueInfo_UNSTABLE()` and `Snapshot#getInfo_UNSTABLE()` always report the node `type`. (#1547)

## 0.5.2 (2021-11-07)

Expand Down
8 changes: 2 additions & 6 deletions packages/recoil/core/Recoil_FunctionalCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export type RecoilValueInfo<T> = {
isActive: boolean,
isSet: boolean,
isModified: boolean, // TODO report modified selectors
type: 'atom' | 'selector' | void, // void until initialized for now
type: 'atom' | 'selector',
deps: Iterable<RecoilValue<mixed>>,
subscribers: {
nodes: Iterable<RecoilValue<mixed>>,
Expand All @@ -194,11 +194,7 @@ function peekNodeInfo<T>(
): RecoilValueInfo<T> {
const storeState = store.getState();
const graph = store.getGraph(state.version);
const type = storeState.knownAtoms.has(key)
? 'atom'
: storeState.knownSelectors.has(key)
? 'selector'
: undefined;
const type = getNode(key).nodeType;
const downstreamNodes = filterIterable(
getDownstreamNodes(store, state, new Set([key])),
nodeKey => nodeKey !== key,
Expand Down
6 changes: 3 additions & 3 deletions packages/recoil/core/__tests__/Recoil_Snapshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ testRecoil('getInfo', () => {
isActive: false,
isSet: false,
isModified: false,
type: undefined,
type: 'atom',
});
expect(Array.from(snapshot.getInfo_UNSTABLE(myAtom).deps)).toEqual([]);
expect(
Expand All @@ -370,7 +370,7 @@ testRecoil('getInfo', () => {
isActive: false,
isSet: false,
isModified: false,
type: undefined,
type: 'selector',
});
expect(Array.from(snapshot.getInfo_UNSTABLE(selectorA).deps)).toEqual([]);
expect(
Expand All @@ -381,7 +381,7 @@ testRecoil('getInfo', () => {
isActive: false,
isSet: false,
isModified: false,
type: undefined,
type: 'selector',
});
expect(Array.from(snapshot.getInfo_UNSTABLE(selectorB).deps)).toEqual([]);
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ testRecoil(
isActive: false,
isSet: false,
isModified: false,
type: undefined,
type: 'atom',
});
expect(Array.from(getRecoilValueInfo(myAtom).deps)).toEqual([]);
expect(Array.from(getRecoilValueInfo(myAtom).subscribers.nodes)).toEqual(
Expand All @@ -89,7 +89,7 @@ testRecoil(
isActive: false,
isSet: false,
isModified: false,
type: undefined,
type: 'selector',
});
expect(Array.from(getRecoilValueInfo(selectorA).deps)).toEqual([]);
expect(Array.from(getRecoilValueInfo(selectorA).subscribers.nodes)).toEqual(
Expand All @@ -105,7 +105,7 @@ testRecoil(
isActive: false,
isSet: false,
isModified: false,
type: undefined,
type: 'selector',
});
expect(Array.from(getRecoilValueInfo(selectorB).deps)).toEqual([]);
expect(Array.from(getRecoilValueInfo(selectorB).subscribers.nodes)).toEqual(
Expand Down
2 changes: 1 addition & 1 deletion typescript/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
isActive: boolean;
isSet: boolean;
isModified: boolean; // TODO report modified selectors
type: 'atom' | 'selector' | undefined; // undefined until initialized for now
type: 'atom' | 'selector';
deps: Iterable<RecoilValue<T>>;
subscribers: {
nodes: Iterable<RecoilValue<T>>,
Expand Down

0 comments on commit 69acb21

Please sign in to comment.