mithril.js icon indicating copy to clipboard operation
mithril.js copied to clipboard

Simplify the router to just use render functions

Open dead-claudia opened this issue 4 years ago • 1 comments

Mithril version:

Browser and OS:

Project:

Is this something you're interested in implementing yourself? Very.

Description

Change the routes in the router to just be "route": (attrs) => vnode functions.

// Current
m.route(elem, "/", {
	"/": Home,
	"/foo/:id": FooView,
})

// Proposed
m.route(elem, "/", {
	"/": () => m(Home),
	"/foo": ({id}) => m(FooView, {id}),
})

This would also entail making m.route.SKIP work with the render function, so we can retain that core functionality.

Why

Simplifies our router API greatly. Together with a built-in Async component, this covers the full API for route resolvers in a way that's just generally more flexible and pluggable for users. It's also simpler to implement.

Possible Implementation

Open Questions

dead-claudia avatar Aug 07 '19 13:08 dead-claudia

This is unnecessary.

  • Provides unnecessary addition to framework
  • Doesn't create any better code habits. "don't fix what isn't broken"

ycadaner-merkos302 avatar Dec 23 '19 17:12 ycadaner-merkos302