Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export isLoadable() #1312

Closed
wants to merge 4 commits into from

Conversation

drarmstr
Copy link
Contributor

Summary: Export isLoadable() as part of the RecoilLoadable interface for Loadables.

Reviewed By: mondaychen, csantos42

Differential Revision: D31566788

Summary:
Pull Request resolved: facebookexperimental#1263

Expose factory interface for creating `Loadable` objects.  Note that `Loadable` is not a class due to limitations with Flow not supporting disjoint unions with class properties.  Therefore, I don't think we can export `Loadable` as a type as well as an object containing static factories.  So, use `Load` instead... :(

Proposed interface examples:

```
const valueLoadable = RecoilLoadable.of('VALUE');
```

```
const pendingLoadable = RecoilLoadable.of(Promise.resolve('ASYNC VALUE'));
```

```
const errorLoadable = RecoilLoadable.error(new Error('ERROR'));
```

D31040527 adds `RecoilLoadable.all()`

Differential Revision: D31038573

fbshipit-source-id: 24d28d4435d3714549b7f30b77038a7f72754f0c
Summary: Use the new public Loadable factory interface in recoil-sync library

Differential Revision: D31038775

fbshipit-source-id: 510039b50d4f5dd3ca64af937ad0f663ea606f84
Summary:
Pull Request resolved: facebookexperimental#1264

Add a `Load.all()` factory for Loadables analogous to `Promise.all()`:

```
Load.all([ Load.of('abc'), Load.of(123) ]).contents
['abc', 123]
```

Also provide an object version in addition to an array version:

```
Load.all({ str: Load.of('abc'), num: Load.of(123) }).contents
{str: abc, num: 123}
```

This also works nested:

```
Load.all([
  Load.all([Load.of('a'), Load.of('b')]),
  Load.all([Load.of(1), Load.of(2)]),
]).contents

[ ['a','b'], [1,2] ]
```

And it support async inputs:
```
Load.all([ Load.of(Promise.resolve('async')), Load.of('sync') ]).map(values => {
  values is ['async', 'sync']
});
```

Note TypeScript should have the proper tuple and object mapping, but not sure how to enable that for Flow since the factory is nested in `Load` object...

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

fbshipit-source-id: 66fd83ade0a2c1db71efe3ee5a95be763c1e43df
Summary: Export `isLoadable()` as part of the `RecoilLoadable` interface for Loadables.

Reviewed By: mondaychen, csantos42

Differential Revision: D31566788

fbshipit-source-id: 87360c4f752cc3cc05c725e27febd6d18679db60
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported labels Oct 19, 2021
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31566788

@drarmstr drarmstr self-assigned this Oct 19, 2021
@drarmstr drarmstr added the enhancement New feature or request label Oct 19, 2021
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 36016ae.

@drarmstr drarmstr deleted the export-D31566788 branch October 19, 2021 22:06
AlexGuz23 pushed a commit to AlexGuz23/Recoil that referenced this pull request Nov 3, 2022
Summary:
Pull Request resolved: facebookexperimental/Recoil#1312

Export `isLoadable()` as part of the `RecoilLoadable` interface for Loadables.

Reviewed By: mondaychen, csantos42

Differential Revision: D31566788

fbshipit-source-id: c160bd4d1d1635ef39bb2cd5c29e49431399a252
snipershooter0701 pushed a commit to snipershooter0701/Recoil that referenced this pull request Mar 5, 2023
Summary:
Pull Request resolved: facebookexperimental/Recoil#1312

Export `isLoadable()` as part of the `RecoilLoadable` interface for Loadables.

Reviewed By: mondaychen, csantos42

Differential Revision: D31566788

fbshipit-source-id: c160bd4d1d1635ef39bb2cd5c29e49431399a252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants