Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 2, 2020
1 parent e4ecc36 commit 763806f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
59 changes: 43 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,68 @@

// Modules
const Plugin = require('@overlook/plugin'),
{INIT_CHILDREN} = require('@overlook/route'),
{INIT_ROUTE, INIT_CHILDREN} = require('@overlook/route'),
reactPlugin = require('@overlook/plugin-react'),
staticPlugin = require('@overlook/plugin-static');
staticPlugin = require('@overlook/plugin-static'),
{findParentOrSelf} = require('@overlook/util-find-parent'),
assert = require('simple-invariant');

// Imports
const pkg = require('../package.json');

// Exports

// TODO Replace once `plugin-bundle` is written
const BUNDLE_ADD_ENTRY = Symbol('@overlook/plugin-bundle.BUNDLE_ADD_ENTRY');

module.exports = new Plugin(
pkg,
[staticPlugin, reactPlugin],
{symbols: ['GET_REACT_ROOT_FILE']},
(Route, {GET_REACT_ROOT_FILE, REACT_FILE}) => class ReactRootRoute extends Route {
(Route, {
GET_REACT_ROOT_FILE, REACT_FILE, REACT_ROOT, STATIC_FILE
}) => class ReactRootRoute extends Route {
/**
* Set this route as React root.
* @returns {undefined}
*/
async [INIT_ROUTE]() {
// Define `[REACT_ROOT]` before calling superclass, so it's defined
// before `plugin-react`'s `[INIT_ROUTE]()` method executes.
this[REACT_ROOT] = this;

// Delegate to super classes
await super[INIT_ROUTE]();

// TODO Remove this once `plugin-bundle` is written
this[BUNDLE_ADD_ENTRY] = () => undefined;
}

/**
* Add React file to bundle.
* @returns {undefined}
*/
async [INIT_CHILDREN]() {
// Delegate to super classes
await super[INIT_CHILDREN]();

const file = this[GET_REACT_ROOT_FILE](); // eslint-disable-line no-unused-vars
const file = this[GET_REACT_ROOT_FILE]();

// TODO Pass to `@overlook/plugin-bundle` to be entry file
// this[ADD_ENTRY](file);
// Pass to `@overlook/plugin-bundle` as entry file
const bundleRoute = findParentOrSelf(this, route => route[BUNDLE_ADD_ENTRY]);
assert(bundleRoute, 'React root or a route above it must use `@overlook/plugin-bundle`');

// Record HTML file to be served as static file
this[STATIC_FILE] = bundleRoute[BUNDLE_ADD_ENTRY](file);
}

/**
* Get React file for root.
* Can be extended in subclasses.
* @returns {Object} - File
*/
[GET_REACT_ROOT_FILE]() {
return this[REACT_FILE];
}

/*
async [BUNDLE]() {
await super[BUNDLE]();
// TODO Get HTML file from bundle
const htmlFile = ...
this[STATIC_FILE] = htmlFile;
}
*/
}
);
11 changes: 7 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
},
"dependencies": {
"@overlook/plugin": "^0.4.1",
"@overlook/plugin-react": "0.0.2",
"@overlook/plugin-react": "0.2.1",
"@overlook/plugin-static": "^0.3.2",
"@overlook/route": "^0.6.5",
"react-dom": "^16.13.1"
"@overlook/util-find-parent": "^0.1.0",
"react-dom": "^16.13.1",
"simple-invariant": "^2.0.0"
},
"devDependencies": {
"@overlookmotel/eslint-config": "^7.2.1",
Expand Down

0 comments on commit 763806f

Please sign in to comment.