Commit graph

1193 commits

Author SHA1 Message Date
impinball
d7ef127be2 Isolate m.prop() and m.deferred() implementations (mostly)
This mostly isolates the implementations for both of these. Now, everything
here calls the method itself, not any of the external methods.

Few driveby fixes as well:

1. Git now ignores archive/ again (it's a build artifact, and can be removed
   when updating `master`)
2. Since I had to rewrite most of the Deferred implementation, the new version
   passes one of the skipped tests, so it is now enabled.
2015-11-20 02:49:48 -05:00
Leo Horie
edc5dca238 Merge pull request #846 from bewildergeist/lowercase-npm-package-name
Revert to lowercase NPM package name
2015-11-13 08:42:55 -05:00
Dan Okkels Brendstrup
101d4523b4 Revert to lowercase NPM package name
As per https://docs.npmjs.com/files/package.json#name as mentioned by @Pumpuli
in #845.
2015-11-13 08:40:08 +01:00
Leo Horie
5269f9b1ce don't use non-standard trim, dies on Travis CI 2015-11-12 23:42:27 -05:00
Leo Horie
4de23eb5c8 Merge remote-tracking branch 'origin/next' into next 2015-11-12 23:31:06 -05:00
Leo Horie
28366212b0 prevent IE error #810 2015-11-12 23:30:50 -05:00
Leo Horie
0b4ec86221 Merge pull request #835 from PaulAvery/next
Do not use `window` when it is not available
2015-11-12 22:47:33 -05:00
Leo Horie
12cc183687 Merge pull request #845 from bewildergeist/one-config-to-rule-them-all
Read version number + other info from package.json
2015-11-12 22:39:35 -05:00
Leo Horie
04afc9a2c5 stop eslint nag 2015-11-12 22:36:05 -05:00
Leo Horie
e3e2fba060 remove broken badge 2015-11-12 18:54:08 -05:00
Dan Okkels Brendstrup
0c38f9ec1c Read version number + other info from package.json 2015-11-12 23:53:04 +01:00
Leo Horie
92c9334006 don't break concat scripts 2015-11-12 16:28:58 -05:00
Leo Horie
db66d89bc5 Merge pull request #844 from bewildergeist/fix-license
Fix MIT license annotation in package.json
2015-11-12 16:07:46 -05:00
Dan Okkels Brendstrup
d20c0a77bb Fix MIT license annotation in package.json
As per https://docs.npmjs.com/files/package.json#license
2015-11-12 21:54:50 +01:00
Leo Horie
e9e8b0922f Merge pull request #837 from sisidovski/fix_sample
Change m.mount to m.component in sample html
2015-11-12 14:32:02 -05:00
Leo Horie
6971d85d28 Merge pull request #841 from cnatis/patch-1
Fixed syntax error in example
2015-11-12 14:03:35 -05:00
Christian Natis
a3410b8f3e Fixed syntax error in example 2015-11-12 10:56:46 -05:00
Leo Horie
e62eaed0fd Merge pull request #838 from impinball/patch-4
Misread ESLint docs...(meant to allow `x|0`)
2015-11-11 23:27:19 -05:00
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
sisidovski
b36b9868c5 Change m.mount to m.component in sample html 2015-11-12 04:34:20 +09: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
Florian Albertz
814b5035ee Do not use window when it is not available 2015-11-07 14:37:29 +01: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