Dynamic loading for Editor

This commit is contained in:
Jori Lallo
2018-01-03 20:08:43 -08:00
parent c504bfdc83
commit 2fd5fc2dff
5 changed files with 91 additions and 72 deletions

View File

@@ -1,5 +1,8 @@
{ {
"presets": ["react", "env"], "presets": [
"react",
"env"
],
"plugins": [ "plugins": [
"lodash", "lodash",
"styled-components", "styled-components",
@@ -7,11 +10,14 @@
"transform-es2015-destructuring", "transform-es2015-destructuring",
"transform-object-rest-spread", "transform-object-rest-spread",
"transform-regenerator", "transform-regenerator",
"transform-class-properties" "transform-class-properties",
"syntax-dynamic-import"
], ],
"env": { "env": {
"development": { "development": {
"presets": ["react-hmre"] "presets": [
"react-hmre"
]
} }
} }
} }

View File

@@ -25,8 +25,8 @@ import DocumentsStore from 'stores/DocumentsStore';
import CollectionsStore from 'stores/CollectionsStore'; import CollectionsStore from 'stores/CollectionsStore';
import DocumentMenu from 'menus/DocumentMenu'; import DocumentMenu from 'menus/DocumentMenu';
import SaveAction from './components/SaveAction'; import SaveAction from './components/SaveAction';
import type EditorType from 'components/Editor';
import LoadingPlaceholder from 'components/LoadingPlaceholder'; import LoadingPlaceholder from 'components/LoadingPlaceholder';
import Editor from 'components/Editor';
import LoadingIndicator from 'components/LoadingIndicator'; import LoadingIndicator from 'components/LoadingIndicator';
import Collaborators from 'components/Collaborators'; import Collaborators from 'components/Collaborators';
import CenteredContent from 'components/CenteredContent'; import CenteredContent from 'components/CenteredContent';
@@ -56,6 +56,7 @@ class DocumentScene extends Component {
props: Props; props: Props;
savedTimeout: number; savedTimeout: number;
@observable editorComponent;
@observable editCache: ?string; @observable editCache: ?string;
@observable newDocument: ?Document; @observable newDocument: ?Document;
@observable isLoading = false; @observable isLoading = false;
@@ -65,6 +66,7 @@ class DocumentScene extends Component {
componentDidMount() { componentDidMount() {
this.loadDocument(this.props); this.loadDocument(this.props);
this.loadEditor();
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@@ -128,6 +130,11 @@ class DocumentScene extends Component {
} }
}; };
loadEditor = async () => {
const EditorImport = await import('components/Editor');
this.editorComponent = EditorImport.default;
};
get isEditing() { get isEditing() {
return ( return (
this.props.match.path === matchDocumentEdit || this.props.newDocument this.props.match.path === matchDocumentEdit || this.props.newDocument
@@ -208,6 +215,7 @@ class DocumentScene extends Component {
} }
render() { render() {
const Editor = this.editorComponent;
const isNew = this.props.newDocument; const isNew = this.props.newDocument;
const isMoving = this.props.match.path === matchDocumentMove; const isMoving = this.props.match.path === matchDocumentMove;
const document = this.document; const document = this.document;
@@ -225,7 +233,7 @@ class DocumentScene extends Component {
{isMoving && document && <DocumentMove document={document} />} {isMoving && document && <DocumentMove document={document} />}
{titleText && <PageTitle title={titleText} />} {titleText && <PageTitle title={titleText} />}
{(this.isLoading || this.isSaving) && <LoadingIndicator />} {(this.isLoading || this.isSaving) && <LoadingIndicator />}
{!document ? ( {!document || !Editor ? (
<CenteredContent> <CenteredContent>
<LoadingState /> <LoadingState />
</CenteredContent> </CenteredContent>

View File

@@ -68,6 +68,7 @@
"babel-loader": "^7.1.2", "babel-loader": "^7.1.2",
"babel-plugin-lodash": "^3.2.11", "babel-plugin-lodash": "^3.2.11",
"babel-plugin-styled-components": "^1.1.7", "babel-plugin-styled-components": "^1.1.7",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1", "babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "1.3.4", "babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-plugin-transform-es2015-destructuring": "^6.23.0", "babel-plugin-transform-es2015-destructuring": "^6.23.0",

View File

@@ -697,6 +697,10 @@ babel-plugin-syntax-decorators@^6.1.18:
version "6.13.0" version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-decorators/-/babel-plugin-syntax-decorators-6.13.0.tgz#312563b4dbde3cc806cee3e416cceeaddd11ac0b" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-decorators/-/babel-plugin-syntax-decorators-6.13.0.tgz#312563b4dbde3cc806cee3e416cceeaddd11ac0b"
babel-plugin-syntax-dynamic-import@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-dynamic-import/-/babel-plugin-syntax-dynamic-import-6.18.0.tgz#8d6a26229c83745a9982a441051572caa179b1da"
babel-plugin-syntax-exponentiation-operator@^6.8.0: babel-plugin-syntax-exponentiation-operator@^6.8.0:
version "6.13.0" version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de"