Merge branch 'next' into perf

This commit is contained in:
Leo Horie 2014-11-25 19:59:06 -05:00
commit 2110335f87
4 changed files with 42 additions and 38 deletions

View file

@ -2,7 +2,7 @@
---
- [How auto-redrawing-works](#how-auto-redrawing-works)
- [How auto-redrawing works](#how-auto-redrawing-works)
- [Integrating multiple execution threads](#integrating-multiple-execution-threads)
- [Integrating to legacy code](#integrating-to-legacy-code)
- [Signature](#signature)
@ -242,4 +242,4 @@ void startComputation()
```clike
void endComputation()
```
```

View file

@ -68,32 +68,6 @@ That organization pattern needlessly ties unrelated aspects of the application t
---
## Global Namespace Hygiene
For developer convenience, Mithril uses the global `m` variable as a namespace, much like jQuery uses `$`.
If you want to ensure global namespace hygiene, you can wrap your code in "islands" like this:
```javascript
new function(m) {
//your code goes here
}(Mithril);
```
If you are creating components to be used by 3rd parties, it's recommended that you always use this idiom.
In the unlikely case that you have another global variable called `m` in your page, you should consider renaming it to make it more descriptive, or use the idiom below to keep it intact.
```markup
<script>_temp = m</script>
<script src="mithril.js"></script>
<script>m = _temp</script>
```
---
## Usage of m.redraw
`m.redraw` is a method that allows you to render a template outside the scope of Mithril's auto-redrawing system.

View file

@ -1,4 +1,4 @@
Mithril = m = new function app(window, undefined) {
var m = (function app(window, undefined) {
var OBJECT = "[object Object]", ARRAY = "[object Array]", STRING = "[object String]", FUNCTION = "function";
var type = {}.toString;
var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/;
@ -362,7 +362,8 @@ Mithril = m = new function app(window, undefined) {
function clear(nodes, cached) {
for (var i = nodes.length - 1; i > -1; i--) {
if (nodes[i] && nodes[i].parentNode) {
nodes[i].parentNode.removeChild(nodes[i]);
try {nodes[i].parentNode.removeChild(nodes[i])}
catch (e) {} //ignore if this fails due to order of events (see http://stackoverflow.com/questions/21926083/failed-to-execute-removechild-on-node)
cached = [].concat(cached);
if (cached[i]) unload(cached[i])
}
@ -580,11 +581,16 @@ Mithril = m = new function app(window, undefined) {
element.removeEventListener("click", routeUnobtrusive);
element.addEventListener("click", routeUnobtrusive)
}
//m.route(route)
//m.route(route, params)
else if (type.call(arguments[0]) == STRING) {
currentRoute = arguments[0];
var querystring = arguments[1] != null && type.call(arguments[1]) == OBJECT ? buildQueryString(arguments[1]) : null;
if (querystring) currentRoute += (currentRoute.indexOf("?") === -1 ? "?" : "&") + querystring;
var args = arguments[1] || {}
var queryIndex = currentRoute.indexOf("?")
var params = queryIndex > -1 ? parseQueryString(currentRoute.slice(queryIndex + 1)) : {}
for (var i in args) params[i] = args[i]
var querystring = buildQueryString(params)
var currentPath = queryIndex > -1 ? currentRoute.slice(0, queryIndex) : currentRoute
if (querystring) currentRoute = currentPath + (currentPath.indexOf("?") === -1 ? "?" : "&") + querystring;
var shouldReplaceHistoryEntry = (arguments.length == 3 ? arguments[2] : arguments[1]) === true;
@ -654,7 +660,7 @@ Mithril = m = new function app(window, undefined) {
var pairs = str.split("&"), params = {};
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split("=");
params[decodeSpace(pair[0])] = pair[1] ? decodeSpace(pair[1]) : (pair.length === 1 ? true : "")
params[decodeSpace(pair[0])] = pair[1] ? decodeSpace(pair[1]) : ""
}
return params
}
@ -971,7 +977,7 @@ Mithril = m = new function app(window, undefined) {
m.deps.factory = app;
return m
}(typeof window != "undefined" ? window : {});
})(typeof window != "undefined" ? window : {});
if (typeof module != "undefined" && module !== null) module.exports = m;
if (typeof define == "function" && define.amd) define(function() {return m});
if (typeof module != "undefined" && module !== null && module.exports) module.exports = m;
else if (typeof define == "function" && define.amd) define(function() {return m});

View file

@ -1063,7 +1063,7 @@ function testMithril(mock) {
mock.requestAnimationFrame.$resolve()
m.route("/test14?test&test2=")
mock.requestAnimationFrame.$resolve() //teardown
return mock.location.search == "?/test14?test&test2=" && m.route.param("test") === true && m.route.param("test2") === ""
return mock.location.search == "?/test14?test=&test2=" && m.route.param("test") === "" && m.route.param("test2") === ""
})
test(function() {
mock.requestAnimationFrame.$resolve() //setup
@ -1597,6 +1597,30 @@ function testMithril(mock) {
return root.childNodes[0].nodeValue == "b"
})
test(function() {
mock.requestAnimationFrame.$resolve()
mock.location.search = "?"
var root = mock.document.createElement("div")
var a = {}
a.controller = function() {
m.route("/b?foo=1", {foo: 2})
}
a.view = function() {return "a"}
var b = {}
b.controller = function() {}
b.view = function() {return "b"}
m.route(root, "/", {
"/": a,
"/b": b,
})
mock.requestAnimationFrame.$resolve()
return mock.location.search == "?/b?foo=2"
})
//end m.route
//m.prop