diff --git a/examples/src/index.tsx b/examples/src/index.tsx index 76fd55b..8e8636a 100755 --- a/examples/src/index.tsx +++ b/examples/src/index.tsx @@ -25,7 +25,7 @@ const Button = () => class SliderExample extends View { slider = new SliderStore() - view() { + render() { return m('div', [ m('h1', '@codeurs/front'), m('.examples-slider', @@ -70,7 +70,7 @@ const LanguagesNav = () => class ModalExample extends View { modal = new ModalStore() - view() { + render() { return [ m('button', {onclick: this.modal.open}, 'Open modal'), m(Portal, [ @@ -87,7 +87,7 @@ class ModalExample extends View { } class Examples extends View { - view() { + render() { return m(HashRouter, m(Switch, [ m(Route, { diff --git a/src/router/link.ts b/src/router/link.ts index a6eda85..28dd395 100755 --- a/src/router/link.ts +++ b/src/router/link.ts @@ -10,7 +10,7 @@ export class Link extends View<{ onclick?: Function [key: string]: any }> { - view() { + render() { const {to, target, onclick, children, ...attrs} = this.attrs return m(Location, location => { const href = location.formatPath(to) diff --git a/src/router/redirect.ts b/src/router/redirect.ts index f0281cd..6919a20 100755 --- a/src/router/redirect.ts +++ b/src/router/redirect.ts @@ -5,7 +5,7 @@ import {m} from '../hyperscript' export class Redirect extends View<{ to: string }> { - view() { + render() { const {to} = this.attrs return m(Location, location => location.replace(location.formatPath(to))) } diff --git a/src/router/route.ts b/src/router/route.ts index 9e16146..1604908 100755 --- a/src/router/route.ts +++ b/src/router/route.ts @@ -9,7 +9,7 @@ export type RouteAttrs = { } export class Route extends View { - view() { + render() { const {render = this.children} = this.attrs return m(Location, location => { const match = location.match(this.attrs) diff --git a/src/router/router.ts b/src/router/router.ts index 3f22ec5..275844c 100755 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -44,7 +44,7 @@ export class Router extends View { } } - view() { + render() { const {matcher = pathnameMatcher, formatPath = v => v} = this.attrs const {location, history} = window const {protocol, hostname, port, search, hash, pathname} = location diff --git a/src/router/switch.ts b/src/router/switch.ts index 81ac09a..40aef9d 100755 --- a/src/router/switch.ts +++ b/src/router/switch.ts @@ -8,7 +8,7 @@ import {extractChildren} from '../util/children' export class Switch extends View<{ children: Array> }> { - view() { + render() { const {children} = this.attrs return m(Location, location => { for (const child of children) { diff --git a/src/ui/context.ts b/src/ui/context.ts index bd82c5f..9a23c2e 100755 --- a/src/ui/context.ts +++ b/src/ui/context.ts @@ -19,7 +19,7 @@ export type Context = { export const createContext = (context?: T): Context => ({ Provider: class Provider extends View> { - view() { + render() { const received = context const {value, children} = this.attrs context = value @@ -34,7 +34,7 @@ export const createContext = (context?: T): Context => ({ } }, Consumer: class Consumer extends View> { - view() { + render() { const {children} = this.attrs return children(context) } diff --git a/src/ui/portal.ts b/src/ui/portal.ts index 7cfd3ea..16b0f50 100755 --- a/src/ui/portal.ts +++ b/src/ui/portal.ts @@ -14,7 +14,5 @@ export class Portal extends View { document.body.removeChild(this.node) } - view() { - return null - } + render() {} } diff --git a/src/ui/view.ts b/src/ui/view.ts index bb4bd83..b525306 100755 --- a/src/ui/view.ts +++ b/src/ui/view.ts @@ -33,7 +33,7 @@ export abstract class View onBeforeRemove(): void | Promise {} onRemove() {} onBeforeUpdate(attrs: Attr): void | boolean {} - abstract view(): Children + abstract render(): Children /*protected redraw(e?) { if (e) e.redraw = false @@ -44,6 +44,13 @@ export abstract class View // Mithril connection + // Cannot mark view as internal because that wouldn't match mithril externs. + // Method is stubbed because we might need it later on to bypass mithril + // error handling. + view(): Children { + return this.render() + } + /** @internal */ oninit(vnode: CVnode) { this.__update(vnode)