-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore deferred-mount and undo Suspense
- Loading branch information
1 parent
99b03b7
commit 939711d
Showing
12 changed files
with
827 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
packages/@react-facet/core/src/hooks/useFacetUnwrapTransition.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) Microsoft Corporation. | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# @react-facet/deferred-mount | ||
|
||
React Facet is a state management for performant game UIs. For more information on how to use this package check the official documentation available at https://react-facet.mojang.com/. | ||
|
||
This package allows you to defer the mounting of a component to the next frame. By wrapping components on a big list you can keep the frame time low while everything is mounted. | ||
|
||
When the `DeferredMountProvider` is used, it requires that there is at least one descendent as a `DeferredMount` or `DeferredMountWithCallback`, otherwise it will wait forever as `deferring`. | ||
|
||
### Example | ||
|
||
In the example below it will mount: | ||
|
||
- Mounting: nothing | ||
- First Frame: `First` | ||
- Second Frame: `First` and `Second` | ||
- Third Frame: `First`, `Second` and `Third` | ||
|
||
The `useIsDeferring` hook allows to check what is the status of the deferred mounting (by returning a Facet) so we can, for example, show a spinner. | ||
|
||
```tsx | ||
const SampleComponent = () => { | ||
const isDeferringFacet = useIsDeferring() | ||
|
||
return ( | ||
<> | ||
<fast-text text={useFacetMap((isDeferring) => (isDeferring ? 'deferring' : 'done'), [], [isDeferringFacet])} /> | ||
<DeferredMount> | ||
<div>First</div> | ||
</DeferredMount> | ||
<DeferredMount> | ||
<div>Second</div> | ||
</DeferredMount> | ||
<DeferredMount> | ||
<div>Third</div> | ||
</DeferredMount> | ||
</> | ||
) | ||
} | ||
|
||
render( | ||
<DeferredMountProvider frameTimeBudget={16}> | ||
<SampleComponent /> | ||
</DeferredMountProvider>, | ||
document.getElementById('root'), | ||
) | ||
``` | ||
|
||
The `frameTimeBudget` prop allows the tweaking of how much time the library has available to do work on a given frame (by default it targets 60fps). | ||
|
||
## Deferring Asynchronous Renders | ||
|
||
Some components may need to wait some time before they can be considered fully rendered (for example if they are fetching data). For these cases you should use `DeferredMountWithCallback` with the `useNotifyMountComplete` hook. | ||
|
||
### Example | ||
|
||
```tsx | ||
const DelayedComponent = () => { | ||
const notifyMountComplete = useNotifyMountComplete() | ||
const [data, setData] = useState() | ||
|
||
useEffect(() => { | ||
fetch('mock-api').then((data) => { | ||
setData(data) | ||
notifyMountComplete() | ||
}) | ||
}, [notifyMountComplete]) | ||
|
||
return <div>{data}</div> | ||
} | ||
|
||
render( | ||
<DeferredMountProvider> | ||
<DeferredMountWithCallback> | ||
<DelayedComponent /> | ||
</DeferredMountWithCallback> | ||
</DeferredMountProvider>, | ||
document.getElementById('root'), | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-env node */ | ||
|
||
const baseConfig = require('../../../jest.base.config') | ||
const projectName = require('./package.json').name | ||
|
||
module.exports = { | ||
...baseConfig, | ||
name: projectName, | ||
displayName: projectName, | ||
rootDir: './', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"name": "@react-facet/deferred-mount", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Mojang/ore-ui.git", | ||
"directory": "packages/@react-facet/deferred-mount" | ||
}, | ||
"author": { | ||
"name": "Paulo Ragonha", | ||
"email": "paulo@ragonha.me" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Danila Dergachev", | ||
"email": "dderg@protonmail.com" | ||
}, | ||
{ | ||
"name": "Fernando Via Canel", | ||
"email": "fernando.via@gmail.com" | ||
}, | ||
{ | ||
"name": "Marlon Huber-Smith", | ||
"email": "marlonhubersmith@gmail.com" | ||
} | ||
], | ||
"files": [ | ||
"dist/**/*" | ||
], | ||
"homepage": "https://react-facet.mojang.com/", | ||
"bugs": "https://github.com/Mojang/ore-ui/issues", | ||
"license": "MIT", | ||
"version": "0.5.3", | ||
"main": "src/index.tsx", | ||
"publishConfig": { | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "rimraf dist && tsc", | ||
"prepublish": "yarn build" | ||
}, | ||
"peerDependencies": { | ||
"@react-facet/core": "0.5.3", | ||
"react": "^16.9.0" | ||
}, | ||
"devDependencies": { | ||
"@react-facet/dom-fiber-testing-library": "0.5.3", | ||
"react": "^16.9.0", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.8.2" | ||
} | ||
} |
Oops, something went wrong.