Skip to content

Commit

Permalink
Add example for inexistent collection
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioh8010 committed Mar 5, 2024
1 parent 41baa2c commit b1f185d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ const ONYXKEYS = {

/** Collection Keys */
COLLECTION: {
INEXISTENT: 'inexistentCollection_',
DOWNLOAD: 'download_',
POLICY: 'policy_',
POLICY_MEMBERS: 'policyMembers_',
Expand Down Expand Up @@ -452,6 +453,7 @@ type OnyxFormDraftValuesMapping = {
};

type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.INEXISTENT]: {id: string};
[ONYXKEYS.COLLECTION.DOWNLOAD]: OnyxTypes.Download;
[ONYXKEYS.COLLECTION.POLICY]: OnyxTypes.Policy;
[ONYXKEYS.COLLECTION.POLICY_DRAFTS]: OnyxTypes.Policy;
Expand Down
12 changes: 11 additions & 1 deletion src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function SubRenderTest({policy}: {policy: UseOnyxData<`policy_${string}`, OnyxEn
type ComponentWithOnyxHOCOnyxProps = {
account: OnyxEntry<Account>;

inexistentCollection: OnyxCollection<{id: string}>;

policies: OnyxCollection<Policy>;

policy: OnyxEntry<Policy>;
Expand All @@ -36,6 +38,9 @@ const ComponentWithOnyxHOC = withOnyx<ComponentWithOnyxHOCProps, ComponentWithOn
account: {
key: ONYXKEYS.ACCOUNT,
},
inexistentCollection: {
key: ONYXKEYS.COLLECTION.INEXISTENT,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
Expand All @@ -50,10 +55,11 @@ const ComponentWithOnyxHOC = withOnyx<ComponentWithOnyxHOCProps, ComponentWithOn
key: ONYXKEYS.COLLECTION.POLICY,
selector: (policy) => policy?.name as unknown as OnyxCollection<PartialPolicy>,
},
})(({policyID, account, policies, policy, sessionEmail, policiesWithSelector}) => {
})(({policyID, account, inexistentCollection, policies, policy, sessionEmail, policiesWithSelector}) => {
console.group('OnyxPlayground [App] ComponentWithOnyxHOC');
console.log('OnyxPlayground [App] ComponentWithOnyxHOC policyID', policyID);
console.log('OnyxPlayground [App] ComponentWithOnyxHOC account', account);
console.log('OnyxPlayground [App] ComponentWithOnyxHOC inexistentCollection', inexistentCollection);
console.log('OnyxPlayground [App] ComponentWithOnyxHOC policies', policies);
console.log('OnyxPlayground [App] ComponentWithOnyxHOC policy', policy);
console.log('OnyxPlayground [App] ComponentWithOnyxHOC sessionEmail', sessionEmail);
Expand All @@ -75,6 +81,9 @@ function ComponentWithOnyxHook({policyID}: ComponentWithOnyxHookProps) {
const account = useOnyx(ONYXKEYS.ACCOUNT);
const [accountValue] = account;

Check failure on line 82 in src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'accountValue' is assigned a value but never used

const inexistentCollection = useOnyx(ONYXKEYS.COLLECTION.INEXISTENT);
const [inexistentCollectionValue] = inexistentCollection;

Check failure on line 85 in src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'inexistentCollectionValue' is assigned a value but never used

const policies = useOnyx(ONYXKEYS.COLLECTION.POLICY);
const [policiesValue] = policies;

Check failure on line 88 in src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

'policiesValue' is assigned a value but never used

Expand Down Expand Up @@ -108,6 +117,7 @@ function ComponentWithOnyxHook({policyID}: ComponentWithOnyxHookProps) {
console.group('OnyxPlayground [App] ComponentWithOnyxHook');
console.log('OnyxPlayground [App] ComponentWithOnyxHook policyID', policyID);
console.log('OnyxPlayground [App] ComponentWithOnyxHook account', account);
console.log('OnyxPlayground [App] ComponentWithOnyxHook inexistentCollection', inexistentCollection);
console.log('OnyxPlayground [App] ComponentWithOnyxHook policies', policies);
console.log('OnyxPlayground [App] ComponentWithOnyxHook policy', policy);
console.log('OnyxPlayground [App] ComponentWithOnyxHook policy2', policy2);
Expand Down

0 comments on commit b1f185d

Please sign in to comment.