Commit graph

1173 commits

Author SHA1 Message Date
Isiah Meadows
db9786110d Misread ESLint docs...
It was supposed to permit `x|0` as well as `x | 0`.
2015-11-11 21:40:32 -05:00
Leo Horie
ab51a055f5 Merge pull request #836 from impinball/patch-3
Fix #824
2015-11-08 21:34:28 -05:00
Isiah Meadows
40df7f4860 Forgot to lint 2015-11-08 10:46:19 -05:00
Isiah Meadows
685e71d5a5 Fix #824 2015-11-08 10:30:55 -05:00
Leo Horie
df114a4ee2 Merge pull request #828 from impinball/lint
Lint Mithril main
2015-11-03 09:51:07 -05:00
impinball
96bcc81022 Lint Mithril main
This changes enough things to merit a new patch release. It changed a few
implementation details in the process, but it's at least much cleaner.

Be ready for every other currently outstanding PR for this file to have merge
conflicts.
2015-11-03 01:32:17 -05:00
impinball
4902ee7d6f Fix inconsistent setting (ESLint bug) 2015-11-03 00:52:51 -05:00
Isiah Meadows
5a47705e7e Merge pull request #2 from impinball/next 2015-11-02 10:48:33 -05:00
Isiah Meadows
f53e783a57 Merge pull request #1 from lhorie/next 2015-11-02 10:47:43 -05:00
Leo Horie
69f4ae8071 Merge pull request #822 from impinball/lint
Convert tests to Mocha/Chai/Sinon and lint them.
2015-11-02 10:20:45 -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
Leo Horie
bf0890b255 Merge pull request #807 from mrtracy/next
Typescript: Make MithrilVirtualElement and MithrilRoutes non-generic
2015-10-29 21:14:35 -04:00
impinball
8737c7e2c1 Merge remote-tracking branch 'upstream/next' into next 2015-10-27 19:54:28 -04:00
Leo Horie
bec98898ff Merge pull request #814 from philtay/travis
Test against Node.js 0.12 and 4.1
2015-10-17 21:30:14 -04:00
philtay
7278e0ded5 Test against Node.js 0.12 and 4.1 2015-10-18 01:24:33 +02:00
Matt Tracy
da6d525a11 Typescript: Make MithrilVirtualElement non-generic
`MithrilVirtualElement` was recently converted to be generic over `<T extends
MithrilController>`. The element's `children` may then contain other
`MithrilVirtualElement<T>` or `MithrilComponent<T>` elements.

Unfortunately, in common usage of 'm()' this can cause problems with Mithril's type
inference system. If a type is not explicitly provided to `m()`, the "T" of the
returned MithrilVirtualElement<T> will be inferred from its children. The
candidates for T will be the concrete types of the child MithrilComponent<T>; however, if no
candidate type is a subset of *every* candidate type, then TypeScript will be
unable to infer a valid type, and the call to `m()` will not compile.

To improve this behavior, this commit makes MithrilVirtualElement non-generic;
it's child collection can now contain MithrilComponent<MithrilController>, which
matches all valid MithrilComponent. This the same underlying issue as the
previous commit, which made MithrilRoutes non-generic.

The motivation for fixing this is threefold:

1. Because `m()` has so many overloads, in the case where a call to `m()` will
not compile due to the above issue, the syntax error provided by TypeScript is
not helpful.
2. In many cases, users will be calling `m<MithrilController>()` in their code
simply to get it to compile, which provides no additional utility over a
non-generic type and adds significant boilerplate.
3. Explicitly specifying subtypes to `m()` calls provides little utility; at
best, it can check that contained components implement some common interface.
However, type assertions like that can be provided in other places without
having to attach the information to the MithrilVirtualElement.
2015-10-14 17:27:22 -04:00
Matt Tracy
26f68744b5 Improve Typescript definition for MithrilRoutes
The previous definition of MithrilRoutes was generic over <T extends
MithrilController>, with the MithrilRoutes containing a collection of
MithrilComponent<T>.

However, this presents problems with TypeScript's type inference in many common
situations.  For example, consider this usage of m.route():

```
m.route(document.body, "/a", {
    "/a": ComponentA,
    "/b": ComponentB,
})
```
Both `ComponentA` and `ComponentB` implement `MithrilComponent<T extends
MithrilController>`, with each component having a different concrete controller
type (`ControllerA` and `ControllerB`).

However, unless ControllerA's type is a subset of ControllerB's type (or
vice-versa), TypeScript will be unable to infer the type of the MitrilRoutes<T>
returned by m.route(). To get this to compile, a third type which *is* a
subset of both ControllerA and ControllerB would need to be explicity provided:

```
// Both ControllerA and ControllerB implement MithrilController
m.route<MithrilController>(document.body, "/a", {
  "/a": ComponentA,
  "/b": ComponentB,
})
```

This commit makes MithrilRoute non-generic, and instead of containing
MithrilComponent<T extends MithrilRoute>, it contains
MithrilComponent<MithrilController>, which will match all valid
MithrilComponents.

The motivation for this change is twofold:

1. In the case where m.route() does not compile due to type-inference failure,
the resulting syntax error from Typescript is very unhelpful because m.route()
has a number of overloads. Leaving this as is will result in confusion for
downstream users.
2. An assumption that vanishingly little utility is provided by defining
`MithrilRoutes<T extends MithrilController>` over a type more specific than
MithrilController. At most, it could be used to assert that all of your routed
Components meet a more specialized interface, but that same type check could be
accomplished without having to augment MithrilRoutes with that information.
2015-10-14 17:24:19 -04:00
Leo Horie
6f15a9b148 Merge pull request #812 from caseyWebb/use-modern-travisci
Use modern TravisCI platform
2015-10-14 13:29:49 -04:00
Leo Horie
cba577dfd0 Merge pull request #806 from mrtracy/parameterized-components
Typescript: Support for Parameterized Components
2015-10-14 13:28:53 -04:00
Casey Webb
b542bdad3a Use modern TravisCI platform
@see http://docs.travis-ci.com/user/migrating-from-legacy/?utm_source=legacy-notice&utm_medium=banner&utm_campaign=legacy-upgrade
2015-10-10 11:04:22 -04:00
Matt Tracy
1cdb66b20d Typescript: Support for Parameterized Components
Previously, the Typescript definition file did not support parameterized
components. The `component()` function did accept additional arguments, but the
`MithrilComponent<T>` interface did not allow components to have any additional
arguments in either their `controller()` or `view()` methods.

Properly supporting flexible variadic parameters in typescript is somewhat
challenging. Tuple types are close, but would only work if the signature of
`controller` and `view` accepted arrays of arguments:
```
interface MithrilStatic {
  component<TController extend controller, TRest extends any[]>(
    component: ParameterizedMithrilComponent<TController, TRest>,
    ...args:TRest
  ) : TController
}

interface ParameterizedMithrilComponent<TController extend controller, TRest
extends any[]> {
  // Doesn't match mithril's component interface; we want to unpack the contents
  // of TRest
  controller: (args: TRest) => TController,
  view: (ctrl: TController, args: TRest)
}
```

Therefore, I have gone with a more traditional method of defining several
overloads of m.component(), each with a different number of extra parameters.
Because of this, the first four parameters to m.component() will be correctly
type checked (i.e. if the Component's controller defines the parameter, it must
be supplied to m.component). Additional parameters beyond the first four are
allowed, but are caught via an `...args:any[]` and thus are not type checked.
2015-09-30 16:44:45 -04:00
Leo Horie
80f43c260b fix file size in docs 2015-09-28 22:26:41 -04:00
Leo Horie
d6e68d0144 Merge pull request #798 from Petroochio/library-size
Update README gzip size statement
2015-09-23 19:02:30 -04:00
Peter Gyory
9b50235dd6 Update README gzip size statement 2015-09-23 16:41:26 -04:00
impinball
e7ef34ef4e Merge branch 'next' of https://github.com/lhorie/mithril.js into next 2015-08-28 14:26:55 -04:00
Leo Horie
8fa84c33f8 Merge pull request #783 from mt-caret/next
Fix sample code in m.request documentation
2015-08-28 09:49:55 -04:00
Leo Horie
626144f34c Merge pull request #775 from deomitrus/patch-1
Grammar/spelling fix
2015-08-28 09:20:28 -04:00
Leo Horie
e41e84eaad Merge pull request #771 from Zalmoxisus/next
Fix SyntaxError in the render example
2015-08-28 09:20:12 -04:00
Leo Horie
1b326ee18f Merge pull request #781 from mkautzmann/next
Change m.module to m.mount in documentation
2015-08-28 09:19:16 -04:00
Masayuki Takeda
f9953b8f74 m.request: fix sample code in documentation 2015-08-28 22:18:46 +09:00
Matheus Kautzmann
343ffc8d36 m.module -> m.mount: fix sample code in HTML files 2015-08-28 09:07:08 -03:00
Matheus Kautzmann
dfa1da0652 m.module -> m.mount: fix README 2015-08-27 17:05:27 -03: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
Deomitrus
322ec7e120 Grammar/spelling fix 2015-08-24 21:08:40 -04:00
Mihail Diordiev
a746d67267 Fix typo in the example of data binding 2015-08-22 19:43:05 +03:00
Mihail Diordiev
57c9cfa76b Fix SyntaxError in the render example 2015-08-20 01:47:27 +03:00
Leo Horie
d3cbbef4d5 Merge pull request #766 from avesus/patch-2
Module -> mount rename: fix a documentation link
2015-08-18 22:07:44 -04:00
Leo Horie
23a7811ad7 Merge pull request #767 from jakobdamjensen/next
Make m.route.param() return all params
2015-08-18 22:07:18 -04:00
Jakob Dam Jensen
caf1138c31 Make m.route.param() return all params #737 2015-08-18 20:44:58 +02:00
Ivan Borisenko
8a8829c2e1 Module -> mount rename: fix a documentation link 2015-08-18 21:42:08 +03: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
Leo Horie
5944ed026b Merge remote-tracking branch 'origin/next' into next 2015-08-04 15:02:00 -04:00
Leo Horie
cfdc0a27ce add badge for supported source 2015-08-04 15:01:37 -04:00
Leo Horie
ab8af3ea1d Merge pull request #741 from impinball/next
Bump npm version
2015-08-04 14:52:18 -04:00
Leo Horie
fe65aa748c Merge pull request #746 from gregdking/next
#745 Remove references to DOM nodes when unmounting (Follow-up to #727)
2015-08-04 14:51:55 -04:00
Leo Horie
282da527af Merge pull request #753 from marcolamberto/next
Fixes #721. Firefox insertAdjacentHTML updating text nodes
2015-08-04 14:51:36 -04:00
Leo Horie
7b070fd679 Merge pull request #754 from patrkris/closure-externs
Update externs for Google Closure compiler
2015-08-04 14:51:06 -04:00
Patrick Kristiansen
132fe16176 Update externs for Google Closure compiler 2015-08-04 16:57:13 +02:00
Marco Lamberto
713b458aea Better detection for Range support. 2015-08-04 13:01:07 +02:00