-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
95 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// This file includes experimental React APIs exported from the "scheduler" | ||
// npm package. Despite being explicitely marked as unstable some libraries | ||
// already make use of them. This file is not a full replacement for the | ||
// scheduler package, but includes the necessary shims to make those libraries | ||
// work with Preact. | ||
|
||
export const unstable_ImmediatePriority = 1; | ||
export const unstable_UserBlockingPriority = 2; | ||
export const unstable_NormalPriority = 3; | ||
export const unstable_LowPriority = 4; | ||
export const unstable_IdlePriority = 5; | ||
|
||
/** | ||
* @param {number} priority | ||
* @param {() => void} callback | ||
*/ | ||
export function unstable_runWithPriority(priority, callback) { | ||
return callback(); | ||
} | ||
|
||
export const unstable_now = | ||
typeof performance === 'object' && typeof performance.now === 'function' | ||
? performance.now.bind(performance) | ||
: () => Date.now(); |
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,39 @@ | ||
import { | ||
unstable_runWithPriority, | ||
unstable_NormalPriority, | ||
unstable_LowPriority, | ||
unstable_IdlePriority, | ||
unstable_UserBlockingPriority, | ||
unstable_ImmediatePriority, | ||
unstable_now | ||
} from 'preact/compat'; | ||
|
||
describe('scheduler', () => { | ||
describe('runWithPriority', () => { | ||
it('should call callback ', () => { | ||
const spy = sinon.spy(); | ||
unstable_runWithPriority(unstable_IdlePriority, spy); | ||
expect(spy.callCount).to.equal(1); | ||
|
||
unstable_runWithPriority(unstable_LowPriority, spy); | ||
expect(spy.callCount).to.equal(2); | ||
|
||
unstable_runWithPriority(unstable_NormalPriority, spy); | ||
expect(spy.callCount).to.equal(3); | ||
|
||
unstable_runWithPriority(unstable_UserBlockingPriority, spy); | ||
expect(spy.callCount).to.equal(4); | ||
|
||
unstable_runWithPriority(unstable_ImmediatePriority, spy); | ||
expect(spy.callCount).to.equal(5); | ||
}); | ||
}); | ||
|
||
describe('unstable_now', () => { | ||
it('should return number', () => { | ||
const res = unstable_now(); | ||
expect(res).is.a('number'); | ||
expect(res > 0).to.equal(true); | ||
}); | ||
}); | ||
}); |
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,19 @@ | ||
import { | ||
unstable_runWithPriority, | ||
unstable_NormalPriority, | ||
unstable_LowPriority, | ||
unstable_IdlePriority, | ||
unstable_UserBlockingPriority, | ||
unstable_ImmediatePriority, | ||
unstable_now | ||
} from '../../src'; | ||
|
||
const noop = () => null; | ||
unstable_runWithPriority(unstable_IdlePriority, noop); | ||
unstable_runWithPriority(unstable_LowPriority, noop); | ||
unstable_runWithPriority(unstable_NormalPriority, noop); | ||
unstable_runWithPriority(unstable_UserBlockingPriority, noop); | ||
unstable_runWithPriority(unstable_ImmediatePriority, noop); | ||
|
||
if (typeof unstable_now() === 'number') { | ||
} |