Merge remote-tracking branch 'origin/next' into components

This commit is contained in:
Leo Horie 2015-02-18 21:41:41 -05:00
commit 2160dc13c1
5 changed files with 180 additions and 62 deletions

View file

@ -1,5 +1,21 @@
## Change Log ## Change Log
[v0.1.31](/mithril/archive/v0.1.31) - maintenance
### News:
- Typescript definitions are more strongly typed
- m.request's `unwrapSuccess` and `unwrapError` callbacks now receive the XMLHttpRequest instance as a second parameter
- 3rd parameter for `m.route(route, params, shouldReplaceHistory)` is now public
- exact routes now have higher precedence than routes w/ variables [#452](https://github.com/lhorie/mithril.js/issues/452)
### Bug Fixes:
- fix routing bug in IE9 [#320](https://github.com/lhorie/mithril.js/issues/320)
- fix ordering bug in m.trust when using HTML entities [#453](https://github.com/lhorie/mithril.js/issues/453)
---
[v0.1.30](/mithril/archive/v0.1.30) - maintenance [v0.1.30](/mithril/archive/v0.1.30) - maintenance
### Bug Fixes: ### Bug Fixes:
@ -8,6 +24,8 @@
- fix module.view's `this` association regression in Haxe environment [#434](https://github.com/lhorie/mithril.js/issues/434) - fix module.view's `this` association regression in Haxe environment [#434](https://github.com/lhorie/mithril.js/issues/434)
- fix array serialization syntax in querystrings [#440](https://github.com/lhorie/mithril.js/issues/440) - fix array serialization syntax in querystrings [#440](https://github.com/lhorie/mithril.js/issues/440)
---
[v0.1.29](/mithril/archive/v0.1.29) - maintenance [v0.1.29](/mithril/archive/v0.1.29) - maintenance
### News: ### News:

View file

@ -164,6 +164,7 @@ In the example below, we take advantage of queuing to debug the AJAX response da
//a FP-friendly console.log //a FP-friendly console.log
var log = function(value) { var log = function(value) {
console.log(value) console.log(value)
return value
} }
var users = m.request({method: "GET", url: "/user"}) var users = m.request({method: "GET", url: "/user"})
@ -507,7 +508,7 @@ where:
The value that populates the returned getter-setter before the request completes. This is useful when using the `background` option, in order to avoid the need for null checks in views that may be attempting to access the returned getter-setter before the asynchronous request resolves. The value that populates the returned getter-setter before the request completes. This is useful when using the `background` option, in order to avoid the need for null checks in views that may be attempting to access the returned getter-setter before the asynchronous request resolves.
- **any unwrapSuccess(any data)** (optional) - **any unwrapSuccess(any data, XMLHttpRequest xhr)** (optional)
A preprocessor function to unwrap the data from a success response in case the response contains metadata wrapping the data. A preprocessor function to unwrap the data from a success response in case the response contains metadata wrapping the data.
@ -523,7 +524,7 @@ where:
The unwrapped data The unwrapped data
- **any unwrapError(any data)** (optional) - **any unwrapError(any data, XMLHttpRequest xhr)** (optional)
A preprocessor function to unwrap the data from an error response in case the response contains metadata wrapping the data. A preprocessor function to unwrap the data from an error response in case the response contains metadata wrapping the data.

View file

@ -73,7 +73,7 @@ m.route(document.body, "/dashboard/johndoe", {
This redirects to the URL `http://server/#/dashboard/johndoe` and yields: This redirects to the URL `http://server/#/dashboard/johndoe` and yields:
```markup ```markup
<body>johndoe</body> <body><div>johndoe</div></body>
``` ```
Above, `dashboard` is a module. It contains a `controller` and a `view` properties. When the URL matches a route, the respective module's controller is instantiated and passed as a parameter to the view. Above, `dashboard` is a module. It contains a `controller` and a `view` properties. When the URL matches a route, the respective module's controller is instantiated and passed as a parameter to the view.

197
mithril.d.ts vendored
View file

@ -1,76 +1,165 @@
//Mithril type definitions for Typescript //Mithril type definitions for Typescript
interface MithrilStatic { interface MithrilStatic {
(selector: string, attributes: Object, children?: any): MithrilVirtualElement;
(selector: string, children?: any): MithrilVirtualElement; (selector: string, attributes: MithrilAttributes, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement;
prop(value?: any): (value?: any) => any; (selector: string, ...children: Array<string|MithrilVirtualElement>): MithrilVirtualElement;
withAttr(property: string, callback: (value: any) => void): (e: Event) => any;
module(rootElement: Node, module?: MithrilModule): Object; prop<T>(promise: MithrilPromise<T>) : MithrilPromiseProperty<T>;
trust(html: string): String; prop<T>(value: T): MithrilProperty<T>;
render(rootElement: Element, children?: any): void; prop(): MithrilProperty<Object>; // might be that this should be Property<any>
render(rootElement: HTMLDocument, children?: any): void;
redraw: { withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any;
(): void;
strategy(key: string); module<T extends MithrilController>(rootElement: Node, module: MithrilModule<T>): T;
}; module<T extends MithrilController>(rootElement: Node): T;
route: {
(rootElement:Element, defaultRoute:string, routes:{ [key: string]: MithrilModule }): void trust(html: string): string;
(element: Element, isInitialized: boolean): void;
(rootElement:HTMLDocument, defaultRoute:string, routes:{ [key: string]: MithrilModule }): void; render(rootElement: Element|HTMLDocument): void;
(path:string, params?:any, shouldReplaceHistory?:boolean): void; render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void;
(): string; render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void;
param(key:string): string;
mode: string; redraw: {
}; (force?: boolean): void;
request(options: MithrilXHROptions): MithrilPromise; strategy: MithrilProperty<string>;
deferred(): MithrilDeferred; }
sync(promises: MithrilPromise[]): MithrilPromise;
startComputation(): void; route: {
endComputation(): void; <T extends MithrilController>(rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes<T>): void;
deps(Object: any): Object; <T extends MithrilController>(rootElement: Element, defaultRoute: string, routes: MithrilRoutes<T>): void;
(element: Element, isInitialized: boolean): void;
(path: string, params?: any, shouldReplaceHistory?: boolean): void;
(): string;
param(key: string): string;
mode: string;
}
request<T>(options: MithrilXHROptions): MithrilPromise<T>;
deferred: {
onerror(e: Error): void;
<T>(): MithrilDeferred<T>;
}
sync<T>(promises: MithrilPromise<T>[]): MithrilPromise<T[]>;
startComputation(): void;
endComputation(): void;
// For test suite
deps: {
(mockWindow: Window): Window;
factory: Object;
}
} }
interface MithrilVirtualElement { interface MithrilVirtualElement {
tag: string; key?: number;
attrs: Object; tag?: string;
children: any; attrs?: MithrilAttributes;
children?: any[];
} }
interface MithrilModule { // Configuration function for an element
controller: Function; interface MithrilElementConfig {
view: Function; (element: Element, isInitialized: boolean, context?: any): void;
} }
interface MithrilDeferred { // Attributes on a virtual element
resolve(value?: any): void; interface MithrilAttributes {
reject(value?: any): void; title?: string;
promise: MithrilPromise; className?: string;
class?: string;
config?: MithrilElementConfig;
} }
interface MithrilPromise { // Defines the subset of Event that Mithril needs
(value?: any): any; interface MithrilEvent {
then(successCallback?: (value: any) => any, errorCallback?: (value: any) => any): MithrilPromise; 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 { interface MithrilXHROptions {
method: string; method?: string;
url: string; url: string;
user?: string; user?: string;
password?: string; password?: string;
data?: any; data?: any;
background?: boolean; background?: boolean;
unwrapSuccess?(data: any): any; unwrapSuccess?(data: any): any;
unwrapError?(data: any): any; unwrapError?(data: any): any;
serialize?(dataToSerialize: any): string; serialize?(dataToSerialize: any): string;
deserialize?(dataToDeserialize: string): any; deserialize?(dataToDeserialize: string): any;
extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string; extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string;
type?(data: Object): void; type?(data: Object): void;
config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest; config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest;
dataType?: string;
} }
declare var Mithril: MithrilStatic; declare var Mithril: MithrilStatic;
declare var m: MithrilStatic; declare var m: MithrilStatic;
declare module 'mithril' { declare module 'mithril' {
export = MithrilStatic; export = m;
} }

View file

@ -648,13 +648,19 @@ var m = (function app(window, undefined) {
window[listener]() window[listener]()
} }
//config: m.route //config: m.route
else if (arguments[0].addEventListener) { else if (arguments[0].addEventListener || arguments[0].attachEvent) {
var element = arguments[0]; var element = arguments[0];
var isInitialized = arguments[1]; var isInitialized = arguments[1];
var context = arguments[2]; var context = arguments[2];
element.href = (m.route.mode !== 'pathname' ? $location.pathname : '') + modes[m.route.mode] + this.attrs.href; element.href = (m.route.mode !== 'pathname' ? $location.pathname : '') + modes[m.route.mode] + this.attrs.href;
element.removeEventListener("click", routeUnobtrusive); if (element.addEventListener) {
element.addEventListener("click", routeUnobtrusive) element.removeEventListener("click", routeUnobtrusive);
element.addEventListener("click", routeUnobtrusive)
}
else {
element.detachEvent("onclick", routeUnobtrusive);
element.attachEvent("onclick", routeUnobtrusive)
}
} }
//m.route(route, params) //m.route(route, params)
else if (type.call(arguments[0]) === STRING) { else if (type.call(arguments[0]) === STRING) {
@ -677,7 +683,10 @@ var m = (function app(window, undefined) {
}; };
redirect(modes[m.route.mode] + currentRoute) redirect(modes[m.route.mode] + currentRoute)
} }
else $location[m.route.mode] = currentRoute else {
$location[m.route.mode] = currentRoute
redirect(modes[m.route.mode] + currentRoute)
}
} }
}; };
m.route.param = function(key) { m.route.param = function(key) {
@ -730,8 +739,9 @@ var m = (function app(window, undefined) {
if (e.ctrlKey || e.metaKey || e.which === 2) return; if (e.ctrlKey || e.metaKey || e.which === 2) return;
if (e.preventDefault) e.preventDefault(); if (e.preventDefault) e.preventDefault();
else e.returnValue = false; else e.returnValue = false;
var currentTarget = e.currentTarget || this; var currentTarget = e.currentTarget || e.srcElement;
var args = m.route.mode === "pathname" && currentTarget.search ? parseQueryString(currentTarget.search.slice(1)) : {}; var args = m.route.mode === "pathname" && currentTarget.search ? parseQueryString(currentTarget.search.slice(1)) : {};
while (currentTarget && currentTarget.nodeName.toUpperCase() != "A") currentTarget = currentTarget.parentNode
m.route(currentTarget[m.route.mode].slice(modes[m.route.mode].length), args) m.route(currentTarget[m.route.mode].slice(modes[m.route.mode].length), args)
} }
function setScroll() { function setScroll() {