initial commit
This commit is contained in:
30
visualization-bundle/src/utils/LazyLoadable.tsx
Normal file
30
visualization-bundle/src/utils/LazyLoadable.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import * as React from "react";
|
||||
import { observable, runInAction } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
export function makeLazyLoadable<TProps>(
|
||||
selector: () => Promise<React.ComponentClass<TProps>>
|
||||
): React.ComponentClass<TProps> {
|
||||
@observer
|
||||
class MyComponent extends React.Component<TProps> {
|
||||
@observable
|
||||
component: React.ComponentClass<TProps> | undefined;
|
||||
|
||||
async componentDidMount() {
|
||||
const result = await selector();
|
||||
runInAction("Set Lazily Loaded Component", () => {
|
||||
this.component = result;
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.component) {
|
||||
return <div>Loading...</div>;
|
||||
}
|
||||
const C = this.component;
|
||||
return <C {...this.props} />;
|
||||
}
|
||||
}
|
||||
|
||||
return MyComponent;
|
||||
}
|
||||
13
visualization-bundle/src/utils/index.ts
Normal file
13
visualization-bundle/src/utils/index.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Refinement } from "@hediet/semantic-json/dist/src/serialization/BaseSerializer";
|
||||
|
||||
export function withDeserializer<T, TIntermediate>(
|
||||
fromIntermediate: (val: TIntermediate) => T
|
||||
): Refinement<T, TIntermediate> {
|
||||
return {
|
||||
canSerialize: (val: unknown): val is T => false,
|
||||
fromIntermediate,
|
||||
toIntermediate: () => {
|
||||
throw new Error("not supported");
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user