-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgraded to canary with priority level info
- Loading branch information
Brian Vaughn
committed
May 20, 2019
1 parent
53de5b6
commit d440380
Showing
4 changed files
with
66 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
// @flow | ||
|
||
import React, { Fragment, useCallback, useState } from 'react'; | ||
import { unstable_next as next } from 'scheduler'; | ||
import { | ||
unstable_IdlePriority as IdlePriority, | ||
unstable_LowPriority as LowPriority, | ||
unstable_runWithPriority as runWithPriority, | ||
} from 'scheduler'; | ||
|
||
export default function PriorityLevels() { | ||
const [count, setCount] = useState(0); | ||
const [defaultPriority, setDefaultPriority] = useState<boolean>(false); | ||
const [idlePriority, setIdlePriority] = useState<boolean>(false); | ||
const [normalPriority, setLowPriority] = useState<boolean>(false); | ||
|
||
const resetSequence = useCallback(() => { | ||
setDefaultPriority(false); | ||
setLowPriority(false); | ||
setIdlePriority(false); | ||
}, []); | ||
|
||
const startSequence = useCallback(() => { | ||
setCount(1); | ||
next(() => setCount(2)); | ||
setDefaultPriority(true); | ||
runWithPriority(LowPriority, () => setLowPriority(true)); | ||
runWithPriority(IdlePriority, () => setIdlePriority(true)); | ||
}, []); | ||
|
||
const labels = []; | ||
if (defaultPriority) { | ||
labels.push('(default priority)'); | ||
} | ||
if (normalPriority) { | ||
labels.push('Low Priority'); | ||
} | ||
if (idlePriority) { | ||
labels.push('Idle Priority'); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<h1>Priority Levels</h1> | ||
<button onClick={startSequence}>start sequence</button> | ||
{count >= 1 && <Text>One</Text>} | ||
{count >= 2 && <Text>Two</Text>} | ||
{count >= 2 && ( | ||
<div hidden> | ||
<Text>Three</Text> | ||
</div> | ||
)} | ||
<button onClick={resetSequence}>Reset</button> | ||
<button onClick={startSequence}>Start sequence</button> | ||
<span>{labels.join(', ')}</span> | ||
</Fragment> | ||
); | ||
} | ||
|
||
const Text = ({ children }) => children; |
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