Merge branch 'next' into components

Conflicts:
	mithril.d.ts
This commit is contained in:
Leo Horie 2015-03-25 22:07:11 -04:00
commit 9ada8111d7
4 changed files with 205 additions and 160 deletions

View file

@ -8,6 +8,14 @@ Go to the [Learn Mithril site](http://lhorie.github.io/mithril-blog)
--- ---
### Gitter
There's a [Gitter chat room](https://gitter.im/lhorie/mithril.js). This is a great place to ask questions, discuss ideas and connect with Mithril users.
You can sign in with your Github credentials.
---
### Mailing List ### Mailing List
Looking for a place to talk about Mithril? Suggestions? Looking for a place to talk about Mithril? Suggestions?
@ -27,11 +35,6 @@ Want to help fellow Mithril developers and gain karma while at it? [Keep an eye
### IRC ### IRC
Join the #mithriljs IRC channel on [Freenode](http://webchat.freenode.net). Join the #mithriljs IRC channel on [Freenode](http://webchat.freenode.net).
---
### Gitter
There's also a [Gitter chat room](https://gitter.im/lhorie/mithril.js).
--- ---

9
mithril.d.ts vendored
View file

@ -1,5 +1,5 @@
//Mithril type definitions for Typescript //Mithril type definitions for Typescript
declare module _mithril {
interface MithrilStatic { interface MithrilStatic {
(selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement|MithrilModule>): MithrilVirtualElement; (selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement|MithrilModule>): MithrilVirtualElement;
@ -156,10 +156,11 @@ interface MithrilXHROptions {
config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest; config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest;
dataType?: string; dataType?: string;
} }
}
declare var Mithril: MithrilStatic; declare var Mithril: _mithril.MithrilStatic;
declare var m: MithrilStatic; declare var m: _mithril.MithrilStatic;
declare module 'mithril' { declare module "mithril" {
export = m; export = m;
} }

View file

@ -789,28 +789,44 @@ var m = (function app(window, undefined) {
else window.scrollTo(0, 0) else window.scrollTo(0, 0)
} }
function buildQueryString(object, prefix) { function buildQueryString(object, prefix) {
var str = []; var duplicates = {}
var str = []
for (var prop in object) { for (var prop in object) {
var key = prefix ? prefix + "[" + prop + "]" : prop, value = object[prop]; var key = prefix ? prefix + "[" + prop + "]" : prop
var value = object[prop]
var valueType = type.call(value) var valueType = type.call(value)
var pair = value != null && (valueType === OBJECT) ? var pair = (value === null) ? encodeURIComponent(key) :
buildQueryString(value, key) : valueType === OBJECT ? buildQueryString(value, key) :
valueType === ARRAY ? valueType === ARRAY ? value.reduce(function(memo, item) {
value.map(function(item) {return encodeURIComponent(key + "[]") + "=" + encodeURIComponent(item)}).join("&") : if (!duplicates[key]) duplicates[key] = {}
if (!duplicates[key][item]) {
duplicates[key][item] = true
return memo.concat(encodeURIComponent(key) + "=" + encodeURIComponent(item))
}
return memo
}, []).join("&") :
encodeURIComponent(key) + "=" + encodeURIComponent(value) encodeURIComponent(key) + "=" + encodeURIComponent(value)
str.push(pair) if (value !== undefined) str.push(pair)
} }
return str.join("&") return str.join("&")
} }
function parseQueryString(str) { function parseQueryString(str) {
var pairs = str.split("&"), params = {}; var pairs = str.split("&"), params = {};
for (var i = 0, len = pairs.length; i < len; i++) { for (var i = 0, len = pairs.length; i < len; i++) {
var pair = pairs[i].split("="); var pair = pairs[i].split("=");
params[decodeURIComponent(pair[0])] = pair[1] ? decodeURIComponent(pair[1]) : "" var key = decodeURIComponent(pair[0])
var value = pair.length == 2 ? decodeURIComponent(pair[1]) : null
if (params[key] != null) {
if (type.call(params[key]) !== ARRAY) params[key] = [params[key]]
params[key].push(value)
}
else params[key] = value
} }
return params return params
} }
m.route.buildQueryString = buildQueryString
m.route.parseQueryString = parseQueryString
function reset(root) { function reset(root) {
var cacheKey = getCellCacheKey(root); var cacheKey = getCellCacheKey(root);
clear(root.childNodes, cellCache[cacheKey]); clear(root.childNodes, cellCache[cacheKey]);

View file

@ -1965,7 +1965,7 @@ function testMithril(mock) {
mock.requestAnimationFrame.$resolve() mock.requestAnimationFrame.$resolve()
m.route("/test14?test&test2=") m.route("/test14?test&test2=")
mock.requestAnimationFrame.$resolve() //teardown mock.requestAnimationFrame.$resolve() //teardown
return mock.location.search == "?/test14?test=&test2=" && m.route.param("test") === "" && m.route.param("test2") === "" return mock.location.search == "?/test14?test&test2=" && m.route.param("test") === null && m.route.param("test2") === ""
}) })
test(function() { test(function() {
mock.requestAnimationFrame.$resolve() //setup mock.requestAnimationFrame.$resolve() //setup
@ -3067,6 +3067,31 @@ function testMithril(mock) {
}) })
//end m.route //end m.route
//m.route.parseQueryString
test(function() {
var args = m.route.parseQueryString("foo=bar&hello%5B%5D=world&hello%5B%5D=mars&hello%5B%5D=pluto")
return args["hello[]"] instanceof Array && args["hello[]"].indexOf("world") > -1 && args["hello[]"].indexOf("mars") > -1 && args["hello[]"].indexOf("pluto") > -1
})
test(function() {
var args = m.route.parseQueryString("foo=bar&hello=world&hello=mars&bam=&yup")
return args.foo === "bar" && args.hello[0] === "world" && args.hello[1] === "mars" && args.bam === "" && args.yup === null
})
//m.route.buildQueryString
test(function() {
var string = m.route.buildQueryString({
foo: "bar",
hello: ["world", "mars", "mars"],
world: {
test:3
},
bam: "",
yup: null,
removed: undefined
})
return string === "foo=bar&hello=world&hello=mars&world%5Btest%5D=3&bam=&yup"
})
//m.prop //m.prop
test(function() { test(function() {
var prop = m.prop("test") var prop = m.prop("test")
@ -3187,7 +3212,7 @@ function testMithril(mock) {
test(function() { test(function() {
var prop = m.request({method: "GET", url: "test", data: {foo: [1, 2]}}) var prop = m.request({method: "GET", url: "test", data: {foo: [1, 2]}})
mock.XMLHttpRequest.$instances.pop().onreadystatechange() mock.XMLHttpRequest.$instances.pop().onreadystatechange()
return prop().url === "test?foo%5B%5D=1&foo%5B%5D=2" return prop().url === "test?foo=1&foo=2"
}) })
// m.request over jsonp // m.request over jsonp