Skip to content

Commit

Permalink
Use class for DefaultResolver to improve extensibility
Browse files Browse the repository at this point in the history
  • Loading branch information
askvortsov1 committed Aug 27, 2020
1 parent 11b0941 commit bdd45cb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions js/src/common/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ItemList from './utils/ItemList';
import mixin from './utils/mixin';
import humanTime from './utils/humanTime';
import computed from './utils/computed';
import defaultResolver from './utils/defaultResolver';
import DefaultResolver from './utils/DefaultResolver';
import Drawer from './utils/Drawer';
import anchorScroll from './utils/anchorScroll';
import RequestError from './utils/RequestError';
Expand Down Expand Up @@ -75,7 +75,7 @@ export default {
'utils/mixin': mixin,
'utils/humanTime': humanTime,
'utils/computed': computed,
'utils/defaultResolver': defaultResolver,
'utils/DefaultResolver': DefaultResolver,
'utils/Drawer': Drawer,
'utils/anchorScroll': anchorScroll,
'utils/RequestError': RequestError,
Expand Down
25 changes: 25 additions & 0 deletions js/src/common/utils/DefaultResolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Mithril from 'mithril';

/**
* Generates a route resolver for a given component, to which it provides
* a key as a 'routeName' attr.
*/
export default class DefaultResolver {
component: Mithril.Component;
routeName: string;

constructor(component, routeName) {
this.component = component;
this.routeName = routeName;
}

onmatch(args, requestedPath, route) {
return this.component;
}

render(vnode) {
vnode.attrs.routeName = this.routeName;

return vnode;
}
}
17 changes: 0 additions & 17 deletions js/src/common/utils/defaultResolver.ts

This file was deleted.

4 changes: 2 additions & 2 deletions js/src/common/utils/mapRoutes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import defaultResolver from './defaultResolver.ts';
import DefaultResolver from './DefaultResolver.ts';

/**
* The `mapRoutes` utility converts a map of named application routes into a
Expand All @@ -19,7 +19,7 @@ export default function mapRoutes(routes, basePath = '') {
if ('render' in route.component || 'onmatch' in route.component) {
map[basePath + route.path] = route.component;
} else {
map[basePath + route.path] = defaultResolver(route.component, key);
map[basePath + route.path] = new DefaultResolver(route.component, key);
}
}

Expand Down

0 comments on commit bdd45cb

Please sign in to comment.