Commit graph

53 commits

Author SHA1 Message Date
Isiah Meadows
904b63b2aa
Drop m.version (#2466)
* 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]
2019-07-10 14:04:44 -04:00
Isiah Meadows
1434ba313f
Fix m.version to not depend on package.json (#2464)
* Fix `m.version` to not depend on `package.json`

Created an accidental breaking change.

* Update changelog

* Fix a failing test
2019-07-09 19:26:00 -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
Isiah Meadows
26b8d994ce
Remove m.prop + m.withAttr (#2317)
* 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
2018-11-30 20:41:24 -05:00
Rasmus Porsager
c3896b92e6 output mithril, stream and ospec esm versions on build - fixes #2112 (#2194)
* output mithril, stream and ospec esm versions on build

* Add esm bundles

* [request] Clearer error message for JSON deserialization failure (#2195)

* Bundled output for commit fd7cf8041e [skip ci]

* Fix #1714 conditionally halting stream (#2200)

* Fix #1714 conditionally halting stream

* Add note in changelog

* Do not include stream as named export in mithril.esm.js

* Rename mithril.min.esm.js to mithril.esm.min.js

* Add esm files to eslintignore

* Add named exports

* Add hyperscript `m` as named export

* Add builds with export changes

* checkout regular bundled files

* Change .esm.js to .mjs

* Update pkg module to point to .mjs

* Fix for export names to avoid collision

* Updated bundled files
2018-11-14 15:37:08 -05:00
Isiah Meadows
6042b001f0
Add m.prop (#2268)
Fixes #2095
2018-11-07 12:18:55 -05:00
spacejack
d283b24337 Separate Promise implementation from polyfilling 2018-02-19 23:33:32 +01:00
Pat Cavit
f72aa50f27 Expose Vnode as m.vnode (#1487) 2016-12-20 21:19:16 -08:00
Leo Horie
f54f15d4ce isolate render 2016-12-02 13:22:37 -05:00
Leo Horie
713c25c9c0 fix #1404 2016-12-01 01:45:07 -05:00
Leo Horie
439cf95673 expose promise polyfill in a way that won't need code migration later 2016-11-16 21:15:23 -05:00
Leo Horie
bc8cf4ed76 change m.request return value from stream to promise
remove m.prop
add m.Promise
update tests and examples
2016-11-13 22:44:22 -05:00
Leo Horie
b8ef290acd improved bundler, handle width/height atts 2016-09-23 10:31:33 -04:00
Pierre-Yves Gerardy
057f3a9d2f Fix the bundle and bundle tests 2016-09-03 23:28:17 +02:00
Leo Horie
f201ea73ff ensure internal streams have same constructor as public streams 2016-08-24 01:08:20 -04:00
Leo Horie
17161a05c5 Merge remote-tracking branch 'origin/rewrite' into rewrite
Conflicts:
	mithril.min.js
2016-08-23 13:24:21 -04:00
Leo Horie
6531e3c363 expose parse/build querystring 2016-08-23 13:23:41 -04:00
Pierre-Yves Gerardy
305035f03b Add m.fragment() 2016-08-18 23:34:36 +02:00
Leo Horie
80c25e3809 rename routeresolver methods to {onmatch,view}
expose some piecemeal modules
rename internal xhr to request
mirror internal stream api to match public api
2016-08-17 00:10:47 -04:00
Sebastian Sandqvist
c59ea457c9 fix bundle again 2016-08-15 12:33:57 -07:00
Sebastian Sandqvist
f8d2a50fb7 fix bundle 2016-08-15 12:32:10 -07:00
Sebastian Sandqvist
b8978bec7a remove semicolon 2016-08-15 12:28:45 -07:00
Sebastian Sandqvist
4e1ab37a0e bundle 2016-08-15 12:20:02 -07:00
Sebastian Sandqvist
7bdb29bbfc Piecemeal stream usage 2016-08-15 12:09:22 -07:00
Rasmus Porsager
a0db85b18c Temporary fix for broken bundles
The current bundles were throwing "Stream is not a function".
The proper place to fix this would probably be in the bundler, but for now this circumvents the issue.
It appears the instantiated "Stream" will be cached and used inside the requestService that also requires './util/stream',  instead of just what's inside './util/stream'.
2016-08-14 04:06:14 +02:00
Leo Horie
6c3036e5c6 fix event removal in diff
fix CI
2016-08-12 22:08:02 -04:00
Leo Horie
2ee15e3639 fix stream uncaught error reporting
fix stream JSON stringification
rename internal render function to `use`
2016-08-12 00:41:44 -04:00
Leo Horie
640b19228a improve bundler 2016-07-28 22:35:22 -04:00
Leo Horie
d8b48666f4 rebuild 2016-07-15 01:22:47 -04:00
Gilbert
008ffc9587 Add m.prop.sync 2016-07-12 23:27:36 -05:00
Leo Horie
89492a4956 modularize bundler and minify scripts 2016-06-23 01:10:30 -04:00
Leo Horie
bce2abbffd Merge remote-tracking branch 'origin/rewrite' into rewrite
Conflicts:
	docs/keys.md
	docs/signatures.md
	docs/v1.x-migration.md
	index.js
	ospec/bin/ospec.cmd
	request/request.js
	request/tests/test-xhr.js
	util/prop.js
	util/tests/index.html
	util/tests/test-prop.js
2016-06-20 09:34:14 -04:00
Leo Horie
b9ce90765d streams implementation 2016-06-20 09:21:25 -04:00
impinball
b4fb21475c Add editorconfig, resolve differences
This includes newlines, tabs, among other things.
2016-06-18 03:22:12 -04:00
Leo Horie
6ff63b224c expose m to window 2016-06-07 10:57:20 -04:00
Leo Horie
ddc430a6d3 fix most gcc warnings 2016-06-03 23:55:31 -04:00
Leo Horie
9a396c5173 use promise polyfill 2016-06-01 15:44:08 -04:00
Leo Horie
8e95ecc741 fix typo 2016-05-27 08:17:37 -04:00
Leo Horie
41ac2bf002 rename ajaxt o xhr, expose jsonp 2016-05-26 15:22:36 -04:00
Leo Horie
477e73f300 prop and withAttr work in progress 2016-05-21 01:48:11 -04:00
Leo Horie
e1473dcce8 fiddling w/ bundled var names 2016-05-21 01:20:54 -04:00
Leo Horie
9b602edf4e create only one renderer 2016-05-21 00:59:33 -04:00
Leo Horie
749b952392 clean up index.js 2016-05-21 00:48:58 -04:00
Leo Horie
0005cf26ee refactor redraw into pubsub and autoredraw
- pubsub is a basic pubsub impl
- autoredraw is glue code to register callback to pubsub and onevent

moved e.redraw to autoredraw
2016-05-21 00:37:34 -04:00
Leo Horie
acd9d5b641 Merge branch 'bundler-fix' into rewrite
Conflicts:
	api/mount.js
	api/router.js
	api/tests/test-router.js
	index.js
2016-05-20 22:45:51 -04:00
Leo Horie
e5391a1957 bundler variable disambiguation 2016-05-20 22:38:10 -04:00
Pat Cavit
71c77ba603 Add m.redraw() support for multiple mount points
To better match `0.2.x` behavior: https://jsfiddle.net/xbpyqL9k/
2016-05-20 15:27:17 -07:00
Leo Horie
977239d207 rename limiter to throttle and refactor
- don't inject raf/setTimeout since we can't really mock them w/ a good degree of timing accuracy anyways

fix some unrelated tests
2016-05-19 23:24:04 -04:00