Commit graph

169 commits

Author SHA1 Message Date
Yorhel
c9f185c6c9 Shrinking 2024-10-01 13:21:35 +02:00
Stephan Hoyer
e9a365c150 Kick promise polyfill 2022-05-30 08:38:13 +02:00
Stephan Hoyer
517661a606 allow trailing slash for routes - fixes #2763 2022-05-30 08:34:05 +02:00
Stephan Hoyer
99d1b3270d Fix wording 2022-02-27 18:54:30 +01:00
Stephan Hoyer
94774e73b0 Center docs again 2022-02-27 18:54:11 +01:00
Stephan Hoyer
885b3f9442 Consistent naming of Mithril.js 2022-02-19 12:06:39 +01:00
Stephan Hoyer
9128d4e60a Correctly handle invalid escapes in routes
based on 0a5ead31c9fbd7b153c521c7f9d3df7bf826ce6c
2022-02-18 07:05:35 +01:00
Barney Carroll
38e2184c6d Tests use hyperscript instead of manually constructing nodes 2022-02-12 12:19:35 +01:00
Isiah Meadows
9f0dc2ab46
Runtime-deprecate ospec, change change-log to changelog, fix a few assorted bugs (#2578) 2020-09-29 13:27:07 -07:00
Isiah Meadows
d4551f49f5
Add streams to releases again, include minified bundle, drop in… (#2539)
* Minify stream, add stream stuff to releases again

* Kill off a lot of tech debt, drop internal utilities from npm

1. Kill `module/`, internalize `bundler/`, privatize `test-utils/`

We've been telling people to move elsewhere from these for a while, and
it's about time we just pull the plug here and finally remove them.

- We officially removed the bundler from the public API in v2.0, and
  that was the only one of these that was ever publicly documented.
  Usage should be low enough by now it shouldn't break anyone- I'm not
  seeing bundler bugs being reported anymore, either.
- The `module/` utility was so narrow and caveat-filled that I'm not
  sure anyone really used it (even us core Mithril devs never really
  used it), and we only had it documented in the repo folder it lived
  in. I think only one bug was ever filed, and it's because it somehow
  ended up completely non-functional without any of us realizing it.
- The test utilities were meant to be internal from day 1, but people
  started using it despite us core developers constantly telling people
  to look elsewhere and even the docs recommending specific alternatives
  without mention of our internal mocks. (Now if people would RTFM,
  that'd be nice...)

2. Add dedicated HTML test files to verify ospec and the promise
   polyfill, and ensure the promise tests are in pure ES5.

These are made specially for those and should be much easier to just run
now.

3. Fix the benchmark script to use the real DOM in browsers and to not
   require as many dependencies to create. Also, tweak them to be much
   more effective and precise on what's being tested.

Previously, it was rendering to the HTML file itself, while now it's
rendering to the `body`. This means in browsers, it's triggering layout
and everything, benchmarking how well Mithril optimizes for style and
layout recalcs, too. It also puts some pressure on the hyperscript
parser attribute application, so that can be noticed as well.

* Update dependencies
2019-10-03 04:58:14 -04:00
Isiah Meadows
34f4363357
Add m.censor, adjust m.route.Link to use it (#2538)
Also, restructure a few things for better code reuse.
2019-09-30 18:44:39 -04:00
Isiah Meadows
3fa1630f91
Add params: to m.route.Link, fix docs (#2537) 2019-09-30 17:16:24 -04:00
Isiah Meadows
b98ab29efd
Make errors and their messages more accurate and helpful (#2536)
Also, I normalized them to all be sentences for consistency, and I moved
the reentrancy check from `m.mount` to `m.render` to be a little more
helpful. The router change during mounting is inconsequential and only
to avoid the new modified error, and the change to the update loop is to
send the original error if an error occurred while initializing the
default route. (This is all around more useful anyways.)

And while I was at it, I fixed an obscure bug with sync redraws.
2019-09-30 16:08:04 -04:00
Isiah Meadows
4cbcaf2936
Fix link + docs (#2476)
* 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.
2019-07-16 16:03:24 -04:00
Isiah Meadows
c2f269c3b4
Fix design bug (#2475) 2019-07-16 07:16:25 -04:00
Isiah Meadows
6e57a0691c
Fix #2470 (#2471) 2019-07-12 16:27:24 -04:00
Isiah Meadows
582bda56dc
Partially recast the router API to be a lot more intuitive. (#2469)
* Recast the router API to be a lot more intuitive.

Fixes #2387
Fixes #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
2019-07-12 15:29:37 -04:00
Isiah Meadows
1f4b2cf49a
Deservicify core (#2458)
* 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]
2019-07-07 18:28:43 -04:00
Isiah Meadows
90bcff0fa7
Deduplicate m.route and m.redraw logic (#2453)
- 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.
2019-07-05 18:52:06 -04:00
Isiah Meadows
58f1c74394
Streamline route/request path handling and split params + body in requests (#2361)
Fixes #2360
Fixes #1138
Fixes #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.
2019-05-29 09:28:40 -04:00
Yogesh Khatri
a9172f1129 Feature onmatch route param (#2371)
* added route param in onmatch

* fix docs

* included test

* docs fix
2019-02-07 05:12:53 -05:00
Isiah Meadows
462fb659d7
Fix event handler this value, simplify redraw handling (#2320)
Shaves 10 bytes off the bundle from smaller name + reduced indirection
2018-12-03 06:35:27 -05:00
Isiah Meadows
4a641092dc
Officially drop IE9-10 support, pull out our hacks (#2296)
- 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
2018-11-27 18:04:15 -05:00
magikstm
e64a322bcf Correct test scripts 2017-12-30 04:44:00 -05:00
Patrik Johnson
131e61002e Enable setting navigation options with m.route.link API 2017-10-29 12:21:23 +02:00
Pierre-Yves Gérardy
8a4280eb42 api/redraw, console check for IE9 compat. 2017-09-25 17:03:48 +02:00
Pierre-Yves Gérardy
cf9a31b7b0 api/redraw: Log render() errors. 2017-09-24 21:09:36 +02:00
Pierre-Yves Gérardy
8ab31790ab Merge pull request #1592 from pygy/async-redraw
Make m.redraw() purely asynchronous, add m.redraw.sync()
2017-07-17 23:16:44 +02:00
Pierre-Yves Gérardy
4df43499be Merge pull request #1889 from pygy/fix-1857
Don't overwrite the options object when redirecting from onmatch with m.route.set
2017-07-06 21:10:03 +02:00
Pierre-Yves Gérardy
198f9ca7a9 Reset e.redraw when it was set to false. fixes #1850 2017-07-06 19:48:47 +02:00
Pierre-Yves Gérardy
67b11f156a Add a test to ensure that e.redraw is cleared if it was false 2017-07-06 19:48:47 +02:00
Pierre-Yves Gérardy
a867754d6a Don't overwrite the options object when redirecting from onmatch with m.route.set, fix #1857 2017-07-05 23:58:01 +02:00
Pierre-Yves Gérardy
0e0ed7c45d Lint 2017-06-14 00:15:08 +02:00
Pierre-Yves Gérardy
7de0124339 Tests for m.redraw.sync() 2017-06-13 23:22:25 +02:00
Pierre-Yves Gérardy
ccb3d61675 Make redraw monolithic, add m.redraw.sync 2017-06-13 16:27:54 +02:00
Pierre-Yves Gerardy
b004c20f0c Make m.redraw() strictly asynchronous 2017-06-13 15:20:29 +02:00
Gyandeep Singh
daf5a64697 Chore: Fix lint issues and add indent with tabs 2017-03-11 15:54:41 -06:00
Isiah Meadows
1cc5fa5ba7 "use strict" and other linty fixes 2017-03-03 18:24:38 -05:00
Pierre-Yves Gerardy
2196f5c909 Add test-utils/components.js to index.html where needed 2017-02-21 09:16:08 +01:00
Pierre-Yves Gerardy
fca89f987f Tests: enable the three kind of components in all related files but api/tests/test-route.js 2017-02-19 02:14:15 +01:00
Pierre-Yves Gerardy
ac38335453 Tests: Wrap some component definitions in createComponent() calls
These are the ones that would have been tedious to automate.
jscodeshift will handle the remaining ones
2017-02-19 02:14:15 +01:00
Pierre-Yves Gerardy
f96319e6f6 Tests: add dummy forEach blocks around sections with components 2017-02-19 02:14:15 +01:00
Pierre-Yves Gerardy
a8e5189f0b Tests: factory => closure components 2017-02-19 02:14:15 +01:00
Pierre-Yves Gerardy
d7f39a8254 Tests: group together tests with/without components 2017-02-19 02:14:15 +01:00
Pierre-Yves Gerardy
f273b012c9 Add support for (m.mount + m.route) × (factory + constructible) components 2017-02-15 21:58:42 +01:00
Pierre-Yves Gerardy
f4fb5ac4be Tests for routes that resolve to class and factory components 2017-02-15 21:58:41 +01:00
Pierre-Yves Gerardy
9e65e6bf47 Tests for mounting class and factory components 2017-02-15 21:58:41 +01:00
Leo
a89e8cd405 add docs about mixed keys 2017-02-03 22:56:34 -05:00
Leo
9d5f686bbd #1579 prevent infinite loop in non-existent default route 2017-02-03 22:21:14 -05:00
Pat Cavit
d119accb21 fix: m.route.param, not m.route.params 😓 2017-01-11 15:14:29 -08:00