* 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
* 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]
- 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.
* 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
This relies on a hack to bypass the `mocha` detection by `grunt-mocha-phantomjs`.
The tests have to run in less than 10 seconds, which is unlikely to be problematic on current
hardware.
Alternatively, adding the following to tests/index.html also makes the old test suite compatible
with the mocha runner, but it entails loading `mocha`:
<script src="../node_modules/mocha/mocha.js"></script>
<script>
mocha.setup("bdd")
describe("dummy test", function(){
it("is a dummy test to run the old test suite with grunt-mocha-phantomjs like the new one", function(){})
})
mocha.run()
</script>
Details:
1. All tests now live in `test`. All test dependencies that aren't from npm live
in `test-deps`.
2. The QUnit tests are gone, as well as their dependencies. Half of them
duplicated existing tests, and some of them depended on the real DOM to
properly test.
3. All tests are now using Mocha to run the tests, Chai for assertions, and
Sinon and Sinon Chai for testing some callbacks.
4. Tests are run through mocha-phantomjs. If you want to run just the tests,
run `grunt mocha_phantomjs` or fire up a server in the root and open
`http://localhost:<port>/test/index.html`, e.g. `python3 -m http.server`.
5. The linter I chose is ESLint. It is relatively easy to configure, but with a
lot of flexibility. The rules I chose mostly were in tune to the style the
project was already using. I'm not including a style guide in this commit,
but one will likely come. You can check out the `.eslintrc` in the root and
in `test/` for the two configs. The `.eslintignore` includes a TODO for
`mithril.js` itself targeted at me, in the root.
Other info:
- As a drive-by fix, I fixed line endings on a few of the files.
- I also took care of a few other files and linted them as I went:
- `Gruntfile.js`
- `test/input-cursor.html` (was in `tests/`)
- `test/svg.html` (was in `tests/`)
- `docs/layout/tools/template-converter.html`
- `docs/layout/tools/template-converter.js`
I didn't test the template converter after linting it, because it needs
further scrutiny to ensure it works with the latest version of Mithril. I
know the API has changed a little, which is why I want to be sure.
- I simplified the `.travis.yml` file because none of the tests are run directly
through Node anymore. They are always run in a browser of some kind.
Hopefully, this turned out all right...