Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Code-split article preview page that requires the markdown lib
Browse files Browse the repository at this point in the history
  • Loading branch information
microbouji committed May 13, 2020
1 parent cbe1f0f commit 522fe6f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
5 changes: 0 additions & 5 deletions app/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {CRegisterComponent} from "../pages/register.comp";
import {RouterOutlet} from "../router/router-outlet";
import {ComponentRegistry} from "./component-registry";
import {ProfileComponent} from "../pages/profile.comp";
import {ArticlePreviewComponent} from "../pages/article-preview.comp";
import {CommentPreviewComponent} from "../components/comment-preview.comp";
import {EditorComponent} from "../pages/editor.comp";
import {SettingsComponent} from "../pages/settings.comp";
Expand Down Expand Up @@ -61,10 +60,6 @@ const components = [
tagName: 'c-profile',
component: ProfileComponent
},
{
tagName: 'article-preview',
component: ArticlePreviewComponent
},
{
tagName: 'comment-preview',
component: CommentPreviewComponent
Expand Down
7 changes: 4 additions & 3 deletions app/pages/article-preview.comp.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {Http} from "../http/http";
"use strict";
var markdown = require("markdown").markdown;


export class ArticlePreviewComponent extends HTMLElement {
class ArticlePreviewComponent extends HTMLElement {
constructor(params) {
super();
this.slug = params.slug;
Expand Down Expand Up @@ -105,3 +103,6 @@ export class ArticlePreviewComponent extends HTMLElement {


}

window.customElements.define('article-preview', ArticlePreviewComponent);
export default ArticlePreviewComponent;
10 changes: 8 additions & 2 deletions app/router/router-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {CLoginComponent} from "../pages/login.comp";
import {AuthDefender} from "../auth/auth-defender";
import {SettingsComponent} from "../pages/settings.comp";
import {EditorComponent} from "../pages/editor.comp";
import {ArticlePreviewComponent} from "../pages/article-preview.comp";
import {ProfileComponent} from "../pages/profile.comp";
import {CRegisterComponent} from "../pages/register.comp";
import {HomeComponent} from "../pages/home.comp";
Expand Down Expand Up @@ -42,7 +41,6 @@ export class RouterHandler {
{path: '/login', resolve: CLoginComponent},
{path: '/register', resolve: CRegisterComponent},
{path: '/profile/:username', resolve: ProfileComponent},
{path: '/article/:slug', resolve: ArticlePreviewComponent},
{path: '/editor/:slug', resolve: EditorComponent, canActivate: AuthDefender.canActivate},
{path: '/editor', resolve: EditorComponent, canActivate: AuthDefender.canActivate}
];
Expand All @@ -51,6 +49,14 @@ export class RouterHandler {
RouterHandler.inject(new HomeComponent())
}).resolve();

this.router.on(
'/article/:slug',
(params) => {
import('../pages/article-preview.comp.js').then((Component) =>
RouterHandler.inject(new Component.default(params))
);
}).resolve();

routes.forEach(route => {
this.router.on(
route.path,
Expand Down
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

Expand Down

0 comments on commit 522fe6f

Please sign in to comment.