Commit graph

77 commits

Author SHA1 Message Date
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
Patrik Johnson
131e61002e Enable setting navigation options with m.route.link API 2017-10-29 12:21:23 +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
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 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
a8e5189f0b Tests: factory => closure components 2017-02-19 02:14:15 +01:00
Pierre-Yves Gerardy
f4fb5ac4be Tests for routes that resolve to class and factory components 2017-02-15 21:58:41 +01: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
Pat Cavit
2cdd8a96d1 tests: undefined until a route has been matched 2017-01-11 14:25:19 -08:00
Pat Cavit
834dd02610 feat: bring back m.route.params()
Because it's annoying only having route params available to the
top-level components within a route.
2017-01-11 14:23:42 -08:00
Leo Horie
9ad16858a5 #1520 ospec: report duplicate test names 2017-01-08 13:05:27 -05:00
Bryce Gibson
eadd9a0768 Ensure the test checks the right thing. 2016-12-24 09:36:24 +11:00
Leo
d42d728681 fix test 2016-12-23 08:52:09 -05:00
Bryce Gibson
f4084671bc Typo. 2016-12-22 21:16:32 +11:00
Bryce Gibson
088c41a47f Test precondition. 2016-12-22 21:16:32 +11:00
Pierre-Yves Gerardy
703aab7905 [router] Fix hopefully the last race condition 2016-12-09 11:13:42 +01:00
Pierre-Yves Gerardy
605fa44711 [api/router] Test for two deferred onmatch racing 2016-12-08 15:18:37 +01:00
Pierre-Yves Gerardy
3a671fc5ca [router] add tests for onmatch corner cases 2016-12-07 17:07:37 +01:00
Leo Horie
f1f52445ec more router fixes 2016-12-07 07:57:58 -05:00
Leo Horie
992aa30ccc fix m.route.link and m.route.set history replacement 2016-12-06 23:29:15 -05:00
Leo Horie
37cb9a0622 test some more routeresolver cases 2016-12-06 21:59:45 -05:00
Leo Horie
c2acdf6f4a fix and test some edge cases in router 2016-12-06 19:59:39 -05:00
Leo Horie
d8ad94adb2 fix invalidation test 2016-12-06 16:53:16 -05:00
Leo Horie
b6c79f5911 tighten up async testing 2016-12-06 12:43:23 -05:00
Leo Horie
3134202d24 fix tests 2016-12-06 00:09:09 -05:00
Leo Horie
809d8921c9 bypass route resolution algorithm on non-routed redraws 2016-12-05 11:23:25 -05:00
Leo Horie
bb4321e8db Merge remote-tracking branch 'origin/rewrite' into rewrite 2016-12-04 23:36:52 -05:00
Leo Horie
a2b45ff131 add integration test 2016-12-04 23:36:38 -05:00
Pierre-Yves Gerardy
58275417d4 Add test for the context of onmatch and render 2016-12-04 23:49:33 +01:00
Pierre-Yves Gerardy
b6c8e2c63e Add an assertion for RouteResolver.render calls on route.set(route.get()) 2016-12-04 23:38:01 +01:00
Leo Horie
2ffd2fb7e4 throttle m.route redraws 2016-12-04 01:53:39 -05:00
Leo Horie
7368cf6f26 spacing 2016-12-03 09:09:37 -05:00
Leo Horie
713c25c9c0 fix #1404 2016-12-01 01:45:07 -05:00
1111hui
49d678e9a2 double test timeout for test pass in old machine 2016-10-10 16:41:57 +08:00
Leo Horie
cffe77b2c2 tweak timeout in some api/router tests 2016-10-04 16:43:31 -04:00
Pierre-Yves Gerardy
118da88889 Add test for keys on routed components 2016-09-17 22:43:38 +02:00
Pierre-Yves Gerardy
b8673f2ff5 Validate the DOM node passed to render 2016-09-09 15:20:26 +02:00
Pierre-Yves Gerardy
879b9d6883 Adapt tests for debouncedAsync. 2016-09-02 23:05:34 +02:00
Pierre-Yves Gerardy
a34685d7a4 m.route.get() returns the last fully resolved route (fix #1276), change RouteResolver.onmatch() signature according to #1277 2016-09-02 22:03:27 +02:00
Pierre-Yves Gerardy
419897f72c Add test for #1276 2016-09-02 22:00:59 +02:00
Pierre-Yves Gerardy
09578197a1 Mount-based api/router.js
Fix #1180
Fix #1268
Fix #1275
Fix #1286
2016-09-02 21:59:05 +02:00