VNDB fork of mithril.js
`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. |
||
|---|---|---|
| deploy | ||
| docs | ||
| tests | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| .npmignore | ||
| .travis.yml | ||
| dragdrop.html | ||
| Gruntfile.js | ||
| guide.html | ||
| LICENSE | ||
| mithril.closure-compiler-externs.js | ||
| mithril.d.ts | ||
| mithril.js | ||
| mithril.min.js | ||
| mithril.min.js.map | ||
| modulator-test.html | ||
| mvc.html | ||
| onerror.html | ||
| package.json | ||
| README.md | ||
Mithril
A Javascript Framework for Building Brilliant Applications
See the website for documentation
There's also a blog and a mailing list
What is Mithril?
Mithril is a client-side MVC framework - a tool to organize code in a way that is easy to think about and to maintain.
Light-weight
- Only 7kb gzipped, no dependencies
- Small API, small learning curve
Robust
- Safe-by-default templates
- Hierarchical MVC via components
Fast
- Virtual DOM diffing and compilable templates
- Intelligent auto-redrawing system
Sample code
//namespace
var app = {};
//model
app.PageList = function() {
return m.request({method: "GET", url: "pages.json"});
};
//controller
app.controller = function() {
var pages = app.PageList();
return {
pages: pages,
rotate: function() {
pages().push(pages().shift());
}
}
};
//view
app.view = function(ctrl) {
return [
ctrl.pages().map(function(page) {
return m("a", {href: page.url}, page.title);
}),
m("button", {onclick: ctrl.rotate}, "Rotate links")
];
};
//initialize
m.mount(document.getElementById("example"), app);
