* Recast key docs to be much clearer and more accurate [skip ci]
Also, fix a couple broken hash links I noticed while making this.
* Ensure `diff` blocks are highlighted correctly
- Lot of people couldn't migrate to v1 and plan to reevaluate when v2 is
released.
- It's "npm" not "NPM". It doesn't stand for anything, and it never
has - it was initially chosen simply because it was easy to type.
It has a lot of unofficial backronyms with "Node Package Manager"
being one of the most common ones, but it's never officially stood
for anything as an acronym *or* initialism.
- Fixed a few errors in the change log, like non-breaking changes being
included in the "Breaking Changes" section and an inaccuracy in the
summary of a particular change.
- Fixed RawGit URLs to point to GitHack, which is a lighter proxy that
offloads caching to Cloudflare instead of also implementing it itself.
(It also just uses nginx for all the important server logic, so it
scales better.)
- Add a few more v0.2 references as appropriate
* Fix a copy/paste fail
Also, fix some incorrect tests.
* Clarify how routes are diffed, improve key + route resolver docs
- Add some missing links to route resolvers and single-child keyed
fragments, clarify usage around them.
- Drive-by: remove a redundant sentence that itself was missing a
period.
* Actually test for propagation and preventDefault
Previously, the mocks were both junk and inaccurate. No wonder my tests
were silently failing - they were wrong and not obviously wrong.
* 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
* 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.
- 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 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>
Fixes#2360Fixes#1138Fixes#1788 a little less hackishly
Probably fixes a few other issues I'm not aware of.
This more or less goes with @lhorie's comment here, just with a minor name
change from `query` to `params`:
https://github.com/MithrilJS/mithril.js/issues/1138#issuecomment-231363395
Specifically, here's what this patch entails:
- I changed `data` and `useBody` to `params` and `body` in `m.request`.
Migration is trivial: just use `params` or `body` depending on which you
intend to send. Most servers do actually care where the data goes, so you can
generally pretty easily translate this accordingly. If you *really* need the
old behavior, pass the old value in `params` and if `method === "GET"` or
`method === "TRACE"`, also in `body`.
- I opened up all methods to have request bodies.
- I fixed `m.parseQueryString` to prefer later values over earlier values and
to ensure that objects and arrays are persisted across both hash and query
param parsing. That method also accepts an existing key/value map to append
to, to simplify deduplication.
- I normalized path interpolation to be identical between routes and requests.
- I no longer include interpolated values in query strings. If you need to
duplicate values again, rename the interpolation to be a distinct property
and pass the value you want to duplicate as it.
- I converted `m.route` to use pre-compiled routes instead of its existing
system of dynamic runtime checking. This shouldn't have a major effect on
performance short-term, but it'll ease the migration to built-in userland
components and make it a little easier to reconcile. It'll also come handy
for large numbers of routes.
- I added support for matching routes like `"/:file.:ext"` or
`"/:lang-:region"`, giving each defined semantics.
- I added support for matching against routes with static query strings, such
as `"/edit?type=image": { ... }`.
- I'm throwing a few new informative errors.
- And I've updated the docs accordingly.
I also made a few drive-by edits:
- I fixed a bug in the `Stream.HALT` warning where it warned all but the first
usage when the intent was to warn only on first use.
- Some of the tests were erroneously using `Stream.HALT` when they should've
been using `Stream.SKIP`. I've fixed the tests to only test that
`Stream.HALT === Stream.SKIP` and that it only warns on first use.
- The `m.request` and `m.jsonp` docs signatures were improved to more clearly
explain how `m.request(url, options?)` and `m.jsonp(url, options?)` translate
to `m.request(options)` and `m.jsonp(options)` respectively.
-----
There is some justification to these changes:
- In general, it matters surprisingly more than you would expect how things
translate to HTTP requests. So the comment there suggesting a thing that
papers over the difference has led to plenty of confusion in both Gitter and
in GitHub issues.
- A lot of servers expect a GET with a body and no parameters, and leaving
`m.request` open to working with that makes it much more flexible.
- Sometimes, servers expect a POST with query parameters *instead* of a JSON
object. I've seen this quite a bit, even with more popular REST APIs like
Stack Overflow's.
- I've encountered a few servers that expect both parameters and a body, each
with distinct semantic meaning, so the separation makes it much easier to
translate into a request.
- Most of the time, path segments are treated individually, and URL-escaping
the contents is much less error-prone. It also avoids being potentially
lossy, and when the variable in question isn't trusted, escaping the path
segment enables you to pass it through the URL and not risk being redirected
to unexpected locations, avoiding some risks of vulnerabilities and client
side crashes.
If you really don't care how the template and parameters translate to an
eventual URL, just pass the same object for the `params` and `body` and use
`:param...` for each segment. Either way, the more explicit nature should help
a lot in making the intent clearer, whether you care or not.
* Remove `m.prop` + `m.withAttr`
- For many uses, `m.withAttr` is *more* verbose than just directly using
an event handler
- If you're using it with a bound callback, you're literally wasting a
single character in the human readable version (and you're *saving*
them in the minified output).
- It sometimes obscures your intent, if overused.
- Functions are easier to compress than `m.withAttr`, resulting in
slightly smaller bundles.
- `m.withAttr` is overused anyways.
- `m.prop` is basically useless without `m.withAttr`, and the API
doesn't have the same benefits it had with 0.2.x.
* Update changelog
- I also fixed a bunch of related comments
- I had to polyfill `requestAnimationFrame` for Node
- Drive-by: run `eslint . --fix`
- Drive-by: update transpiling info in CONTRIBUTING.md
- Drive-by: we aren't the only ones going semicolon-free
I was stuck on this for a while earlier today: it turns out that `m.route.param` will not return the right results in the `onmatch` function on a `RouterResolver`, though it will inside of a `render` function on the same. This behavior is documented in the `onmatch` section but not the `m.route.param` section, which is where I was looking when I ran up against this earlier.
From an API design perspective it would make sense to me for `m.route.param` to return valid results inside `onmatch`, but I don't know enough about Mithril's internals to know how complex it would be to implement.