Merge branch 'next' into components
Conflicts: mithril.d.ts
This commit is contained in:
commit
9ada8111d7
4 changed files with 205 additions and 160 deletions
|
|
@ -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
|
||||
|
||||
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
|
||||
|
||||
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).
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
285
mithril.d.ts
vendored
285
mithril.d.ts
vendored
|
|
@ -1,165 +1,166 @@
|
|||
//Mithril type definitions for Typescript
|
||||
declare module _mithril {
|
||||
interface MithrilStatic {
|
||||
|
||||
interface MithrilStatic {
|
||||
(selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement|MithrilModule>): MithrilVirtualElement;
|
||||
(selector: string, ...children: Array<string|MithrilVirtualElement|MithrilModule>): MithrilVirtualElement;
|
||||
|
||||
(selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement|MithrilModule>): MithrilVirtualElement;
|
||||
(selector: string, ...children: Array<string|MithrilVirtualElement|MithrilModule>): MithrilVirtualElement;
|
||||
prop<T>(promise: MithrilPromise<T>) : MithrilPromiseProperty<T>;
|
||||
prop<T>(value: T): MithrilProperty<T>;
|
||||
prop(): MithrilProperty<Object>; // might be that this should be Property<any>
|
||||
|
||||
prop<T>(promise: MithrilPromise<T>) : MithrilPromiseProperty<T>;
|
||||
prop<T>(value: T): MithrilProperty<T>;
|
||||
prop(): MithrilProperty<Object>; // might be that this should be Property<any>
|
||||
withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any;
|
||||
|
||||
withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any;
|
||||
module<T extends MithrilController>(rootElement: Node, module: MithrilModule<T>): T;
|
||||
module<T extends MithrilController>(rootElement: Node): T;
|
||||
|
||||
module<T extends MithrilController>(rootElement: Node, module: MithrilModule<T>): T;
|
||||
module<T extends MithrilController>(rootElement: Node): T;
|
||||
trust(html: string): string;
|
||||
|
||||
trust(html: string): string;
|
||||
render(rootElement: Element|HTMLDocument): void;
|
||||
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void;
|
||||
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void;
|
||||
|
||||
render(rootElement: Element|HTMLDocument): void;
|
||||
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void;
|
||||
render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void;
|
||||
redraw: {
|
||||
(force?: boolean): void;
|
||||
strategy: MithrilProperty<string>;
|
||||
}
|
||||
|
||||
redraw: {
|
||||
(force?: boolean): void;
|
||||
strategy: MithrilProperty<string>;
|
||||
}
|
||||
route: {
|
||||
<T extends MithrilController>(rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes<T>): void;
|
||||
<T extends MithrilController>(rootElement: Element, defaultRoute: string, routes: MithrilRoutes<T>): void;
|
||||
|
||||
route: {
|
||||
<T extends MithrilController>(rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes<T>): void;
|
||||
<T extends MithrilController>(rootElement: Element, defaultRoute: string, routes: MithrilRoutes<T>): void;
|
||||
(element: Element, isInitialized: boolean): void;
|
||||
(path: string, params?: any, shouldReplaceHistory?: boolean): void;
|
||||
(): string;
|
||||
|
||||
(element: Element, isInitialized: boolean): void;
|
||||
(path: string, params?: any, shouldReplaceHistory?: boolean): void;
|
||||
(): string;
|
||||
param(key: string): string;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
param(key: string): string;
|
||||
mode: string;
|
||||
}
|
||||
request<T>(options: MithrilXHROptions): MithrilPromise<T>;
|
||||
|
||||
request<T>(options: MithrilXHROptions): MithrilPromise<T>;
|
||||
deferred: {
|
||||
onerror(e: Error): void;
|
||||
<T>(): MithrilDeferred<T>;
|
||||
}
|
||||
|
||||
deferred: {
|
||||
onerror(e: Error): void;
|
||||
<T>(): MithrilDeferred<T>;
|
||||
}
|
||||
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T[]>;
|
||||
|
||||
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T[]>;
|
||||
startComputation(): void;
|
||||
endComputation(): void;
|
||||
|
||||
startComputation(): void;
|
||||
endComputation(): void;
|
||||
// For test suite
|
||||
deps: {
|
||||
(mockWindow: Window): Window;
|
||||
factory: Object;
|
||||
}
|
||||
|
||||
// For test suite
|
||||
deps: {
|
||||
(mockWindow: Window): Window;
|
||||
factory: Object;
|
||||
}
|
||||
}
|
||||
|
||||
interface MithrilVirtualElement {
|
||||
key?: number;
|
||||
tag?: string;
|
||||
attrs?: MithrilAttributes;
|
||||
children?: any[];
|
||||
}
|
||||
|
||||
// Configuration function for an element
|
||||
interface MithrilElementConfig {
|
||||
(element: Element, isInitialized: boolean, context?: any): void;
|
||||
}
|
||||
|
||||
// Attributes on a virtual element
|
||||
interface MithrilAttributes {
|
||||
title?: string;
|
||||
className?: string;
|
||||
class?: string;
|
||||
config?: MithrilElementConfig;
|
||||
}
|
||||
|
||||
// Defines the subset of Event that Mithril needs
|
||||
interface MithrilEvent {
|
||||
currentTarget: Element;
|
||||
}
|
||||
|
||||
interface MithrilController {
|
||||
onunload?(evt: Event): any;
|
||||
}
|
||||
|
||||
interface MithrilControllerFunction extends MithrilController {
|
||||
(): any;
|
||||
}
|
||||
|
||||
interface MithrilView<T extends MithrilController> {
|
||||
(ctrl: T): string|MithrilVirtualElement;
|
||||
}
|
||||
|
||||
interface MithrilModule<T extends MithrilController> {
|
||||
controller: MithrilControllerFunction|{ new(): T };
|
||||
view: MithrilView<T>;
|
||||
}
|
||||
|
||||
interface MithrilProperty<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
toJSON(): T;
|
||||
}
|
||||
|
||||
interface MithrilPromiseProperty<T> extends MithrilPromise<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
toJSON(): T;
|
||||
}
|
||||
|
||||
interface MithrilRoutes<T extends MithrilController> {
|
||||
[key: string]: MithrilModule<T>;
|
||||
}
|
||||
|
||||
|
||||
interface MithrilDeferred<T> {
|
||||
resolve(value?: T): void;
|
||||
reject(value?: any): void;
|
||||
promise: MithrilPromise<T>;
|
||||
}
|
||||
|
||||
interface MithrilSuccessCallback<T, U> {
|
||||
(value: T): U;
|
||||
(value: T): MithrilPromise<U>;
|
||||
}
|
||||
|
||||
interface MithrilErrorCallback<U> {
|
||||
(value: Error): U;
|
||||
(value: string): U;
|
||||
}
|
||||
|
||||
interface MithrilPromise<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
then<U>(success: (value: T) => U): MithrilPromise<U>;
|
||||
then<U>(success: (value: T) => MithrilPromise<U>): MithrilPromise<U>;
|
||||
then<U,V>(success: (value: T) => U, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
|
||||
then<U,V>(success: (value: T) => MithrilPromise<U>, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
|
||||
}
|
||||
interface MithrilXHROptions {
|
||||
method?: string;
|
||||
url: string;
|
||||
user?: string;
|
||||
password?: string;
|
||||
data?: any;
|
||||
background?: boolean;
|
||||
unwrapSuccess?(data: any): any;
|
||||
unwrapError?(data: any): any;
|
||||
serialize?(dataToSerialize: any): string;
|
||||
deserialize?(dataToDeserialize: string): any;
|
||||
extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string;
|
||||
type?(data: Object): void;
|
||||
config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest;
|
||||
dataType?: string;
|
||||
}
|
||||
}
|
||||
|
||||
interface MithrilVirtualElement {
|
||||
key?: number;
|
||||
tag?: string;
|
||||
attrs?: MithrilAttributes;
|
||||
children?: any[];
|
||||
}
|
||||
declare var Mithril: _mithril.MithrilStatic;
|
||||
declare var m: _mithril.MithrilStatic;
|
||||
|
||||
// Configuration function for an element
|
||||
interface MithrilElementConfig {
|
||||
(element: Element, isInitialized: boolean, context?: any): void;
|
||||
}
|
||||
|
||||
// Attributes on a virtual element
|
||||
interface MithrilAttributes {
|
||||
title?: string;
|
||||
className?: string;
|
||||
class?: string;
|
||||
config?: MithrilElementConfig;
|
||||
}
|
||||
|
||||
// Defines the subset of Event that Mithril needs
|
||||
interface MithrilEvent {
|
||||
currentTarget: Element;
|
||||
}
|
||||
|
||||
interface MithrilController {
|
||||
onunload?(evt: Event): any;
|
||||
}
|
||||
|
||||
interface MithrilControllerFunction extends MithrilController {
|
||||
(): any;
|
||||
}
|
||||
|
||||
interface MithrilView<T extends MithrilController> {
|
||||
(ctrl: T): string|MithrilVirtualElement;
|
||||
}
|
||||
|
||||
interface MithrilModule<T extends MithrilController> {
|
||||
controller: MithrilControllerFunction|{ new(): T };
|
||||
view: MithrilView<T>;
|
||||
}
|
||||
|
||||
interface MithrilProperty<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
toJSON(): T;
|
||||
}
|
||||
|
||||
interface MithrilPromiseProperty<T> extends MithrilPromise<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
toJSON(): T;
|
||||
}
|
||||
|
||||
interface MithrilRoutes<T extends MithrilController> {
|
||||
[key: string]: MithrilModule<T>;
|
||||
}
|
||||
|
||||
|
||||
interface MithrilDeferred<T> {
|
||||
resolve(value?: T): void;
|
||||
reject(value?: any): void;
|
||||
promise: MithrilPromise<T>;
|
||||
}
|
||||
|
||||
interface MithrilSuccessCallback<T, U> {
|
||||
(value: T): U;
|
||||
(value: T): MithrilPromise<U>;
|
||||
}
|
||||
|
||||
interface MithrilErrorCallback<U> {
|
||||
(value: Error): U;
|
||||
(value: string): U;
|
||||
}
|
||||
|
||||
interface MithrilPromise<T> {
|
||||
(): T;
|
||||
(value: T): T;
|
||||
then<U>(success: (value: T) => U): MithrilPromise<U>;
|
||||
then<U>(success: (value: T) => MithrilPromise<U>): MithrilPromise<U>;
|
||||
then<U,V>(success: (value: T) => U, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
|
||||
then<U,V>(success: (value: T) => MithrilPromise<U>, error: (value: Error) => V): MithrilPromise<U>|MithrilPromise<V>;
|
||||
}
|
||||
interface MithrilXHROptions {
|
||||
method?: string;
|
||||
url: string;
|
||||
user?: string;
|
||||
password?: string;
|
||||
data?: any;
|
||||
background?: boolean;
|
||||
unwrapSuccess?(data: any): any;
|
||||
unwrapError?(data: any): any;
|
||||
serialize?(dataToSerialize: any): string;
|
||||
deserialize?(dataToDeserialize: string): any;
|
||||
extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string;
|
||||
type?(data: Object): void;
|
||||
config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest;
|
||||
dataType?: string;
|
||||
}
|
||||
|
||||
declare var Mithril: MithrilStatic;
|
||||
declare var m: MithrilStatic;
|
||||
|
||||
declare module 'mithril' {
|
||||
declare module "mithril" {
|
||||
export = m;
|
||||
}
|
||||
|
|
|
|||
38
mithril.js
38
mithril.js
|
|
@ -789,28 +789,44 @@ var m = (function app(window, undefined) {
|
|||
else window.scrollTo(0, 0)
|
||||
}
|
||||
function buildQueryString(object, prefix) {
|
||||
var str = [];
|
||||
for(var prop in object) {
|
||||
var key = prefix ? prefix + "[" + prop + "]" : prop, value = object[prop];
|
||||
var duplicates = {}
|
||||
var str = []
|
||||
for (var prop in object) {
|
||||
var key = prefix ? prefix + "[" + prop + "]" : prop
|
||||
var value = object[prop]
|
||||
var valueType = type.call(value)
|
||||
var pair = value != null && (valueType === OBJECT) ?
|
||||
buildQueryString(value, key) :
|
||||
valueType === ARRAY ?
|
||||
value.map(function(item) {return encodeURIComponent(key + "[]") + "=" + encodeURIComponent(item)}).join("&") :
|
||||
encodeURIComponent(key) + "=" + encodeURIComponent(value)
|
||||
str.push(pair)
|
||||
var pair = (value === null) ? encodeURIComponent(key) :
|
||||
valueType === OBJECT ? buildQueryString(value, key) :
|
||||
valueType === ARRAY ? value.reduce(function(memo, item) {
|
||||
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)
|
||||
if (value !== undefined) str.push(pair)
|
||||
}
|
||||
return str.join("&")
|
||||
}
|
||||
|
||||
function parseQueryString(str) {
|
||||
var pairs = str.split("&"), params = {};
|
||||
for (var i = 0, len = pairs.length; i < len; i++) {
|
||||
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
|
||||
}
|
||||
m.route.buildQueryString = buildQueryString
|
||||
m.route.parseQueryString = parseQueryString
|
||||
|
||||
function reset(root) {
|
||||
var cacheKey = getCellCacheKey(root);
|
||||
clear(root.childNodes, cellCache[cacheKey]);
|
||||
|
|
|
|||
|
|
@ -1965,7 +1965,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") === "" && m.route.param("test2") === ""
|
||||
return mock.location.search == "?/test14?test&test2=" && m.route.param("test") === null && m.route.param("test2") === ""
|
||||
})
|
||||
test(function() {
|
||||
mock.requestAnimationFrame.$resolve() //setup
|
||||
|
|
@ -3067,6 +3067,31 @@ function testMithril(mock) {
|
|||
})
|
||||
//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
|
||||
test(function() {
|
||||
var prop = m.prop("test")
|
||||
|
|
@ -3187,7 +3212,7 @@ function testMithril(mock) {
|
|||
test(function() {
|
||||
var prop = m.request({method: "GET", url: "test", data: {foo: [1, 2]}})
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue