mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) move client code to core
Summary: This moves all client code to core, and makes minimal fix-ups to get grist and grist-core to compile correctly. The client works in core, but I'm leaving clean-up around the build and bundles to follow-up. Test Plan: existing tests pass; server-dev bundle looks sane Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2627
This commit is contained in:
25
app/client/lib/domAsync.ts
Normal file
25
app/client/lib/domAsync.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import {reportError} from 'app/client/models/errors';
|
||||
import {DomContents, onDisposeElem, replaceContent} from 'grainjs';
|
||||
// grainjs annoyingly doesn't export browserGlobals tools, useful for testing in a simulated environment.
|
||||
import {G} from 'grainjs/dist/cjs/lib/browserGlobals';
|
||||
|
||||
/**
|
||||
* Insert DOM contents produced by a Promise. Until the Promise is fulfilled, nothing shows up.
|
||||
* TODO: This would be a handy place to support options to show a loading spinner (perhaps
|
||||
* showing up if the promise takes more than a bit to show).
|
||||
*/
|
||||
export function domAsync(promiseForDomContents: Promise<DomContents>, onError = reportError): DomContents {
|
||||
const markerPre = G.document.createComment('a');
|
||||
const markerPost = G.document.createComment('b');
|
||||
|
||||
// Function is added after the markers, to run once they have been attached to elem (the parent).
|
||||
return [markerPre, markerPost, (elem: Node) => {
|
||||
let disposed = false;
|
||||
promiseForDomContents
|
||||
.then((contents) => disposed || replaceContent(markerPre, markerPost, contents))
|
||||
.catch(onError);
|
||||
|
||||
// If markerPost is disposed before the promise resolves, set insertContent to noop.
|
||||
onDisposeElem(markerPost, () => { disposed = true; });
|
||||
}];
|
||||
}
|
||||
Reference in New Issue
Block a user