-
-
Notifications
You must be signed in to change notification settings - Fork 927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partially recast the router API to be a lot more intuitive. #2469
Conversation
83fd1cb
to
6d82494
Compare
Fixes MithrilJS#2387 Fixes MithrilJS#2072 Fixes quite a few issues reported on Gitter. For `m.route.Link`: - More intuitive - More accessible - More ergonomic - It can be disabled - It can be cancelled - It can be changed - Oh, and you can use it isomorphically. For `m.route.prefix` - You can *read* it. - You can write to it, of course. - It's literally just setting a property. For the router itself (and the rest of Mithril): - You can now `require("mithril")` and all its submodules without a DOM at all. There is a catch: you can't instantiate any routes, you can't mount anything, and you can't invoke `m.render` in any capacity. You can only use `m.route.Link`, `m.route.prefix`, hyperscript stuff, and `mithril/stream`, and you can use `m.request` with `background: true` if you use a global XHR polyfill. (You can't use `m.request` without `background: true` except with a DOM to redraw with.) The goal here is to try to get out of the way for simple testing and to defer the inevitable `TypeError`s for the relevant DOM methods to runtime. The factory requires no arguments, and in terms of globals, you can just figure out based on what errors are thrown what globals to define. Their values don't matter - they just need to be set to *something*, even if it's just `null` or `undefined`, before Mithril executes. Had to make quite a few other changes throughout the docs and tests to update them accordingly. Oh, and that massive router overhaul enabled me to do all this. Also, slip in a few drive-by fixes to the mocks so they're a little easier to work with and can accept more URLs. This was required for a few of the tests.
Apologies for the very large diff on |
Sorry to point this out after the fact but was pondering the I was also wondering if |
@spacejack I wouldn't be against it in the future, but I'd like to flesh out changes to the vnode structure in a separate bug. Short term, I'm correcting the design bug ( |
Sorry if this isn't the right place to ask, but I couldn't find an answer in the docs. I've got a lot of |
@soaxelbrooke I think it should be |
@soaxelbrooke Either use If anyone wants to update the docs to clarify this, I'd be more than willing to accept a pull request. |
Minor suggestion: add a |
@ancmikesmullin For disabling internal links, consider using For the case of external links, please file a new issue for that. I'd definitely be willing to investigate a solution to that, but only separate from this. Do note that nobody else does that, so we'd be among the few that would. (I wouldn't be against it, but I do want to make sure it's reasonably intuitive and that it's done well the first time.) |
Since Mithril started using m.redraw defined as I'm using Mithril isomorphically, and these changes, specifically the usage of requestAnimationFrame in For example, we could have this in
Just to give an idea of what I had to tweek in order to make version 2.0.4 work after the upgrade:
|
@Niklas81 You just need to define a few globals to anything, even if |
But be sure to define those globals before loading Mithril. That's the key. |
Thanks, to keep thinks even simpler and located in the same place in my codebase, you made me realize I can simply replace this:
with this:
|
I motion against built-in components like m.route.Link as a rule regardless of how "ergonomic" they are. oncreate:m.route.link or an onclick: function is just as easy and keeps the framework cleaner. |
Description
m.route.prefix(...)
→m.route.prefix = ...
oncreate: m.route.link
→m(m.route.Link, ...)
m.route.SKIP
Motivation and Context
Fixes #2387
Fixes #2072
Fixes #1792
Fixes #2354 (not in the way they wanted, but it at leasts unblocks them)
Fixes quite a few issues reported on Gitter.
For
m.route.Link
:For
m.route.prefix
For
m.route.SKIP
For the router itself (and the rest of Mithril):
You can now
require("mithril")
and all its submodules without a DOM at all. There is a catch: you can't instantiate any routes, you can't mount anything, and you can't invokem.render
in any capacity. You can only usem.route.Link
,m.route.prefix
, hyperscript stuff, andmithril/stream
, and you can usem.request
withbackground: true
if you use a global XHR polyfill. (You can't usem.request
withoutbackground: true
except with a DOM to redraw with.) The goal here is to try to get out of the way for simple testing and to defer the inevitableTypeError
s for the relevant DOM methods to runtime.The factory requires no arguments, and in terms of globals, you can just figure out based on what errors are thrown what globals to define. Their values don't matter - they just need to be set to something, even if it's just
null
orundefined
, before Mithril executes.Had to make quite a few other changes throughout the docs and tests to
update them accordingly. Oh, and that massive router overhaul enabled me
to do all this.
Also, slip in a few drive-by fixes to the mocks so they're a little
easier to work with and can accept more URLs. This was required for a
few of the tests.
How Has This Been Tested?
Added and updated a lot of tests.
Types of changes
Checklist:
docs/change-log.md