-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataGrid: load more and virtual scrolling (#2799)
- Loading branch information
Showing
29 changed files
with
1,098 additions
and
430 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Large diffs are not rendered by default.
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
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
33 changes: 33 additions & 0 deletions
33
packages/bonito-core/src/util/__tests__/cancellable-promise.spec.ts
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,33 @@ | ||
import { cancellablePromise } from "../cancellable-promise"; | ||
|
||
import { CancelledPromiseError } from "../../errors"; | ||
|
||
describe("Cancellable promise", () => { | ||
test("should cancel promise properly", () => { | ||
const p = Promise.resolve("resolved"); | ||
const cp = cancellablePromise(p); | ||
cp.cancel(); | ||
return expect(cp).rejects.toThrowError(CancelledPromiseError); | ||
}); | ||
|
||
test("should not cancel promise if it is already resolved or rejected", async () => { | ||
const p = Promise.resolve("resolved"); | ||
const cp = cancellablePromise(p); | ||
await expect(cp).resolves.toBe("resolved"); | ||
cp.cancel(); | ||
await expect(cp).resolves.toBe("resolved"); | ||
|
||
const p2 = Promise.reject("rejected"); | ||
const cp2 = cancellablePromise(p2); | ||
await expect(cp2).rejects.toBe("rejected"); | ||
cp2.cancel(); | ||
await expect(cp2).rejects.toBe("rejected"); | ||
}); | ||
|
||
test("should override the promise's own rejection", async () => { | ||
const p = Promise.reject("rejected"); | ||
const cp = cancellablePromise(p); | ||
cp.cancel(); | ||
await expect(cp).rejects.toThrowError("Promise cancelled"); | ||
}); | ||
}); |
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 { CancelledPromiseError } from "../errors"; | ||
|
||
export interface CancellablePromise<T> extends Promise<T> { | ||
cancel: () => void; | ||
} | ||
|
||
export function cancellablePromise<T>(p: Promise<T>): CancellablePromise<T> { | ||
let cancel: () => void = () => null; | ||
const promise = new Promise<T>((resolve, reject) => { | ||
p.then(resolve, reject); | ||
cancel = () => { | ||
reject(new CancelledPromiseError("Promise cancelled")); | ||
}; | ||
}) as CancellablePromise<T>; | ||
|
||
promise.cancel = cancel; | ||
|
||
return promise; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Oops, something went wrong.