* Recast the router API to be a lot more intuitive.
Fixes#2387Fixes#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.
* Update changelog + numbers, add forgotten bundle option
* Add PR numbers to changelog [skip ci]
* Allow continuing to the next match by returning `false`.
* Update numbers again
* Drop `m.version`
It's caused way too much grief over the years, and I've finally decided
it's worth pitching. For those who need it, it's easy to get, especially
if you use it through Node or a build system. And for those who are just
loading it globally, you have to explicitly specify the version anyways,
so you'd be just as golden if you followed it up with a simple inline
script that does `m.version = "the version you loaded"`.
Oh, and also, you shouldn't be coding specifically for version numbers,
either - it's a known anti-pattern. Instead, you should prefer feature
detection and just do the right thing.
* Update changelog [skip ci]
* De-servicify router (mostly)
Still uses the redraw service, but it no longer has an intermediate
service of its own.
Also, did a *lot* of test deduplication in this. About 30-40% of the
router service tests were already tested on the main router API instance
itself.
Bundle size decreased from 9560 to 9548 bytes min+gzip.
* Merge `m.mount` + `m.redraw`, update router
Simplifies the router and redraw mechanism, and makes it much easier to
keep predictable.
Bundle size down to 9433 bytes min+gzip, docs updated accordingly.
* Make `mithril/render` just return the `m.render` function directly.
* Deservicify `m.render`, revise `m.route`
- You now have to use `mithril/render/render` directly if you want an
implicit redraw function. (This will likely be going away in v3.)
- Revise `m.route` to only `key` components
* Add `redraw` to `m.render`, deservicify requests
* Test error logging
* Update docs + changelog [skip ci]
- Babel 7 has a whole different module API
- Traceur is basically dead
- JSX != HTML
- Some bits are just obvious from context what they are
- ES6 docs shouldn't be auto-installing JSX support
- Also, I decided it was worth clearing up some misleading docs in
surrounding areas.
Nobody has asked yet, but I'd like to not form assumptions about the
reader. Also, it's come up on rare occasion a while back, on both GitHub
and Gitter.
- Remove appropriate route change subcriptions when a root is removed
via `m.mount(root, null)`.
- Don't pollute `onpopstate` and friends - use standard event listeners
instead.
- Simplify and streamline subscriptions, in preparation of adding a
`remove` parameter to `m.mount`.
- Change the redraw internals to redraw immediately, with ability to
cancel via returning a sentinel.
- Change `"bleeding-edge"` for `m.version` in `next` to instead just be
the latest `m.version`. (If you're using `next`, you should know what
you're in for.)
- Update tests to be aware of these changes. (Some were failing for
subtle reasons.)
- Drive-by: remove some uses of `string.charAt(n)` and use `string[n]`
instead.
* Fix#2434
* Treat holes as unkeyed, normalize boolean/null/undefined
This brings a lot better consistency with that API, even though it's
slightly breaking. (I had to update a bunch of tests to correspond with
it.)
* Fill in PR number [skip ci]
* Clarify pathname docs, follow spec with fragments
- Valid URLs must not contain a `#` within its fragment.
https://github.com/MithrilJS/mithril.js/issues/2445
- Our docs were a little confusing and misleading - `m.pathname` isn't
aware of URLs, just path names.
- Removed the relevant extension to `m.parseQueryString` required to
support the hash parsing extension. Now we just shave it off and
ignore it.
- Fix support for arbitrary prefixes, so prefixes like `?#` are
handled correctly.
- Add a bunch of tests to cover various areas of confusion and unusual
edge cases.
* Update with PR [skip ci]
* s/xhr/request/g
`m.xhr` was a relic of the rewrite days prior to the release of v1.0.0,
before it was renamed `m.request` to align with v0.2.x. This just strips
some of that legacy naming.
* Make this work with `async`/`await` correctly.
It looked like a V8 bug, but read the two big code comments and follow
their links. It's a bit more subtle than it looks, and V8's in the right
here.
* Fix for #2423. request.data is replaced by body, params is used for querystring interpolation.
* Updated documentation after code review by shadowhand and isiahmeadows
* Convert indentation to tabs
* Replacing m.request.data and m.jsonp.data with params or body.
* Update request.md
Co-authored-by: Isiah Meadows <contact@isiahmeadows.com>