-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: useLoader fallback * docs: changeset Co-authored-by: Belinda Cao <[email protected]>
- Loading branch information
Showing
4 changed files
with
72 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@modern-js/runtime-core": patch | ||
--- | ||
|
||
fix(runtime): useLoader fallback logic |
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,57 @@ | ||
import { createLoaderManager } from '../src/loader/loaderManager'; | ||
|
||
describe('loaderManager', () => { | ||
test('basic usage', async () => { | ||
const initialData = { | ||
loading: false, | ||
reloading: false, | ||
data: 'hello world', | ||
error: null, | ||
}; | ||
|
||
const loaderManager = createLoaderManager({ | ||
[JSON.stringify('1')]: initialData, | ||
}); | ||
|
||
const { add, get, awaitPendingLoaders } = loaderManager; | ||
|
||
add(() => Promise.resolve('hello modern'), { params: '1' }); | ||
add(() => Promise.resolve('hello modern2'), { params: '2', initialData }); | ||
add(() => Promise.reject(new Error('error occurs')), { | ||
params: '3', | ||
initialData, | ||
}); | ||
|
||
const loader1 = get(JSON.stringify('1')); | ||
const loader2 = get(JSON.stringify('2')); | ||
const loader3 = get(JSON.stringify('3')); | ||
|
||
expect(loader1?.result).toEqual(initialData); | ||
expect(loader2?.result).toEqual(initialData); | ||
|
||
loader1?.load(); | ||
loader2?.load(); | ||
loader3?.load(); | ||
|
||
const result = await awaitPendingLoaders(); | ||
|
||
expect(result[JSON.stringify('1')]).toEqual({ | ||
loading: false, | ||
reloading: false, | ||
data: 'hello modern', | ||
error: null, | ||
}); | ||
expect(result[JSON.stringify('2')]).toEqual({ | ||
loading: false, | ||
reloading: false, | ||
data: 'hello modern2', | ||
error: null, | ||
}); | ||
expect(result[JSON.stringify('3')]).toEqual({ | ||
loading: false, | ||
reloading: false, | ||
data: null, | ||
error: 'error occurs', | ||
}); | ||
}); | ||
}); |