Commit graph

306 commits

Author SHA1 Message Date
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
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
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
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
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
Pierre-Yves Gérardy
7de0124339 Tests for m.redraw.sync() 2017-06-13 23:22:25 +02:00
Pierre-Yves Gerardy
b004c20f0c Make m.redraw() strictly asynchronous 2017-06-13 15:20:29 +02:00
Isiah Meadows
1cc5fa5ba7 "use strict" and other linty fixes 2017-03-03 18:24:38 -05: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
d7f39a8254 Tests: group together tests with/without components 2017-02-19 02:14:15 +01:00
Leo
dc42b60687 #1609 fix lifecycle hooks in children of recycled keyed vnode 2017-02-09 08:31:08 -05:00
Leo
1620b147da clean up repo 2017-01-30 11:18:47 -05:00
Leo
6ab2b6b6c3 merge to next 2017-01-30 11:04:14 -05:00
Leo Horie
a2b45ff131 add integration test 2016-12-04 23:36:38 -05:00
Barney Carroll
6b2750ea59 Test case: parse [class] attribute declaration in hyperscript selector 2016-11-19 17:57:22 +00: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
aef4ab16e9 fix tests 2016-10-26 20:27:20 -04:00
Leo Horie
6514a38162 document querystring apis 2016-10-18 10:16:20 -04:00
Pierre-Yves Gerardy
4aaee178bc Fix the test of the old suite leave the new one broken 2016-09-11 17:10:34 +02:00
Pierre-Yves Gerardy
863b82b71a Break a test of the old suite 2016-09-11 16:52:54 +02:00
Pierre-Yves Gerardy
aeb5f05706 Add the old test suite to the grunt task for both local tests and CI
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>
2016-09-11 16:21:45 +02: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
ec07d76fcd m.fragment docs
public api tests
2016-08-24 00:26:15 -04:00
Bruce Lewis
c98f663653 Render booleans as empty strings 2016-06-10 11:00:56 -04:00
Leo Horie
13fdb60f66 clean slate 2016-04-20 20:01:04 -04:00
Leo Horie
04847785a0 Revert "Use common mock for tests."
This reverts commit f589aa2005.
2016-04-19 22:53:59 -04:00
Carroll
ea946f1a0e Empty attributes. Fixes #971 2016-03-03 10:27:26 +00:00
impinball
f589aa2005 Use common mock for tests. 2016-03-02 14:10:30 -05:00
Leo Horie
4f0d479ee7 Merge branch 'lint' of https://github.com/isiahmeadows/mithril.js into isiahmeadows-lint
Conflicts:
	mithril.js
	tests/mithril-tests.js
2016-01-28 18:40:19 -05:00
Leo Horie
6b7ac83dde Merge branch 'next' of github.com:lhorie/mithril.js into next 2016-01-27 11:22:26 -05:00
Leo Horie
3de5cb8aaf allow string keys 2016-01-27 11:22:01 -05:00
impinball
0766d93bac Lint Mithril itself 2016-01-22 16:25:55 -05:00
impinball
fb3a534de0 Lint old tests 2016-01-22 14:07:25 -05:00
John Long
aad2fc3e33 Adds test 2016-01-05 15:03:52 -07:00
Leo Horie
ae60c96a69 clean up finally 2015-12-20 09:29:12 -05:00
Leo Horie
270b20a2b0 v0.2.2-rc.1 2015-12-20 09:14:28 -05:00
impinball
27a3dca013 Move unloading test to where it's supposed to be [ci skip] 2015-12-15 13:52:14 -05:00
Isiah Meadows
df62ed54f5 Merge pull request #695 from pdfernhout/next
Add an interactive test called unloadingTest.html
2015-12-15 11:40:36 -05:00
impinball
12b8f044f1 Convert tests to Mocha/Chai/Sinon and lint them.
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...
2015-10-31 11:07:22 -04:00
impinball
46775ce828 Fix another m.withAttr test 2015-08-24 23:26:06 -04:00
impinball
6320832440 Fix a test to check the correct this 2015-08-24 23:20:21 -04:00
Jakob Dam Jensen
caf1138c31 Make m.route.param() return all params #737 2015-08-18 20:44:58 +02:00
Leo Horie
7a5980631e Merge pull request #739 from dgilland/origin/feature-propify-finally
Don't pass value/reason to promise.finally callback.
2015-08-04 15:03:47 -04:00
pelonpelon
352d093d90 test for correct this on m.withAttr callback 2015-08-01 15:01:38 -05:00
Derrick Gilland
937b20984d Update promise.finally test for non-propagation of promise value to finally callback. 2015-07-27 11:29:08 -04:00
Derrick Gilland
23930871a1 Add finally to promise-like object.
Closes #680
2015-07-24 16:57:45 -04:00