From 7948ef9be5fd2e7c75320f54b40141707f0235f8 Mon Sep 17 00:00:00 2001 From: Chris Bowdon Date: Sun, 7 Sep 2014 18:00:39 +0800 Subject: [PATCH 01/10] TypeScript defs: added return types where missing from MithrilXHROptions. --- mithril.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mithril.d.ts b/mithril.d.ts index 7b2c4cef..ce62806f 100644 --- a/mithril.d.ts +++ b/mithril.d.ts @@ -55,10 +55,10 @@ interface MithrilXHROptions { unwrapError?(data: any): any; serialize?(dataToSerialize: any): string; deserialize?(dataToDeserialize: string): any; - extract?(xhr: XMLHttpRequest, options: MithrilXHROptions); + extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string; type?(data: Object): void; - config?(xhr: XMLHttpRequest, options: MithrilXHROptions) + config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest; } declare var Mithril: MithrilStatic; -declare var m: MithrilStatic; \ No newline at end of file +declare var m: MithrilStatic; From b7cdeaf46e4d412716c8166f98d1d520623f6df7 Mon Sep 17 00:00:00 2001 From: Chris Bowdon Date: Mon, 8 Sep 2014 08:21:47 +0800 Subject: [PATCH 02/10] TypeScript defs: module can actually take a Node --- mithril.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril.d.ts b/mithril.d.ts index ce62806f..1bc1f888 100644 --- a/mithril.d.ts +++ b/mithril.d.ts @@ -5,7 +5,7 @@ interface MithrilStatic { (selector: string, children?: any): MithrilVirtualElement; prop(value?: any): (value?: any) => any; withAttr(property: string, callback: (value: any) => void): (e: Event) => any; - module(rootElement: Element, module: MithrilModule): void; + module(rootElement: Node, module: MithrilModule): void; trust(html: string): String; render(rootElement: Element, children?: any): void; render(rootElement: HTMLDocument, children?: any): void; From 13a7754f2b91021e8895b580490339655308d4d6 Mon Sep 17 00:00:00 2001 From: "C. James Winslow" Date: Wed, 10 Sep 2014 16:19:02 -0700 Subject: [PATCH 03/10] whitespace fixes --- docs/mithril.module.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/mithril.module.md b/docs/mithril.module.md index d76f76a0..3875ca47 100644 --- a/docs/mithril.module.md +++ b/docs/mithril.module.md @@ -62,13 +62,13 @@ The example below shows a component module called `user` being included in a par var dashboard = { controller: function() { this.greeting = "Hello"; - + this.user = new user.controller(); }, view: function(controller) { return [ m("h1", controller.greeting), - + user.view(controller.user) ]; } @@ -158,7 +158,7 @@ where: - **DOMElement rootElement** A DOM element which will contain the view's template. - + - **Module module** A module is supposed to be an Object with two keys: `controller` and `view`. Each of those should point to a Javascript class constructor function @@ -166,11 +166,11 @@ where: The controller class is instantiated immediately upon calling `m.module`. Once the controller code finishes executing (and this may include waiting for AJAX requests to complete), the view class is instantiated, and the instance of the controller is passed as an argument to the view's constructor. - + Note that controllers can manually instantiate child controllers (since they are simply Javascript constructors), and likewise, views can instantiate child views and manually pass the child controller instances down the the child view constructors. - + This "[turtles all the way down](https://en.wikipedia.org/wiki/Turtles_all_the_way_down)" approach is the heart of Mithril's component system. - + Components are nothing more than decoupled classes that can be dynamically brought together as required. This permits the swapping of implementations at a routing level (for example, if implementing widgetized versions of existing components), and class dependency hierarchies can be structurally organized to provide uniform interfaces (for unit tests, for example). From 36f02f54102cd98f292350c576a5907b2035be5f Mon Sep 17 00:00:00 2001 From: "C. James Winslow" Date: Wed, 10 Sep 2014 16:19:20 -0700 Subject: [PATCH 04/10] updated docs --- docs/mithril.module.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/mithril.module.md b/docs/mithril.module.md index 3875ca47..d02fb113 100644 --- a/docs/mithril.module.md +++ b/docs/mithril.module.md @@ -147,7 +147,7 @@ module1.controller = function() { [How to read signatures](how-to-read-signatures.md) ```clike -void module(DOMElement rootElement, Module module) +Object module(DOMElement rootElement, Module module) where: Module :: Object { Controller, void view(Object controllerInstance) } @@ -162,9 +162,9 @@ where: - **Module module** A module is supposed to be an Object with two keys: `controller` and `view`. Each of those should point to a Javascript class constructor function - - The controller class is instantiated immediately upon calling `m.module`. - + + The controller class is instantiated immediately and a reference is returned upon calling `m.module`. + Once the controller code finishes executing (and this may include waiting for AJAX requests to complete), the view class is instantiated, and the instance of the controller is passed as an argument to the view's constructor. Note that controllers can manually instantiate child controllers (since they are simply Javascript constructors), and likewise, views can instantiate child views and manually pass the child controller instances down the the child view constructors. From 343687d5f236d47ad2a54314b84c4cd2413880ee Mon Sep 17 00:00:00 2001 From: "C. James Winslow" Date: Wed, 10 Sep 2014 16:19:43 -0700 Subject: [PATCH 05/10] update typescript definition --- mithril.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril.d.ts b/mithril.d.ts index 7b2c4cef..ad5caed6 100644 --- a/mithril.d.ts +++ b/mithril.d.ts @@ -5,7 +5,7 @@ interface MithrilStatic { (selector: string, children?: any): MithrilVirtualElement; prop(value?: any): (value?: any) => any; withAttr(property: string, callback: (value: any) => void): (e: Event) => any; - module(rootElement: Element, module: MithrilModule): void; + module(rootElement: Element, module: MithrilModule): Object; trust(html: string): String; render(rootElement: Element, children?: any): void; render(rootElement: HTMLDocument, children?: any): void; From 445087c606f9115d0f85059326f2000d62556947 Mon Sep 17 00:00:00 2001 From: "C. James Winslow" Date: Wed, 10 Sep 2014 16:20:42 -0700 Subject: [PATCH 06/10] changed the tests to expect that m.module returns the instance of module.controller that was passed to it --- tests/mithril-tests.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index cafddc10..975ece3f 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -34,20 +34,21 @@ function testMithril(mock) { mock.requestAnimationFrame.$resolve() var root1 = mock.document.createElement("div") - m.module(root1, { + var mod1 = m.module(root1, { controller: function() {this.value = "test1"}, view: function(ctrl) {return ctrl.value} }) var root2 = mock.document.createElement("div") - m.module(root2, { + var mod2 = m.module(root2, { controller: function() {this.value = "test2"}, view: function(ctrl) {return ctrl.value} }) mock.requestAnimationFrame.$resolve() - return root1.childNodes[0].nodeValue === "test1" && root2.childNodes[0].nodeValue === "test2" + return (root1.childNodes[0].nodeValue === "test1" && root2.childNodes[0].nodeValue === "test2") + && (mod1.value && mod1.value === "test1") && (mod2.value && mod2.value === "test2") }) //m.withAttr From 1222eb913a2eaceb5f41d40229d06cbef07ba2cc Mon Sep 17 00:00:00 2001 From: "C. James Winslow" Date: Wed, 10 Sep 2014 16:21:33 -0700 Subject: [PATCH 07/10] return reference to the instantiated controller from m.module --- mithril.js | 1 + 1 file changed, 1 insertion(+) diff --git a/mithril.js b/mithril.js index c0983bb1..56880897 100644 --- a/mithril.js +++ b/mithril.js @@ -455,6 +455,7 @@ Mithril = m = new function app(window, undefined) { modules[index] = module controllers[index] = new module.controller m.endComputation() + return controllers[index] } } m.redraw = function(force) { From 86f58655f17c9045875e0b30528ff71c250e7cc0 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 14 Sep 2014 21:37:23 -0400 Subject: [PATCH 08/10] update change log --- docs/change-log.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/change-log.md b/docs/change-log.md index 44290144..c32a8b7c 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -12,6 +12,7 @@ ### Bug Fixes: - gracefully degrade on IE exceptions when setting invalid values +- fixes for Typescript definition file --- From 70e7dec0ac14321a2eef912ade2b5f0df374f154 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 14 Sep 2014 21:40:03 -0400 Subject: [PATCH 09/10] remove redundant code --- mithril.js | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/mithril.js b/mithril.js index e6e9e333..1946fd77 100644 --- a/mithril.js +++ b/mithril.js @@ -787,36 +787,6 @@ Mithril = m = new function app(window, undefined) { } function identity(value) {return value} - function serializeArray(array, prefix){ - var idx, out = [] - for (idx in array) { - var formatted = (prefix ? prefix : "") + "[]" - if (prefix && typeof array[idx] === "object") formatted = formatted.replace(/\[\]$/i, "[" + idx + "]") - if (typeof array[idx] === "object" && JSON.stringify(array[idx]) === "{}") continue - if (array[idx] instanceof Array) out.push(serializeArray(array[idx], formatted)) - else if(typeof array[idx] === "object") out.push(serializeObject(array[idx], formatted)) - else out.push(encodeURIComponent(formatted) + "=" + encodeURIComponent(array[idx])) - } - return out.join("&") - } - - function serializeObject(obj, prefix) { - var key, out = [] - for (key in obj) { - var formatted = prefix ? prefix + "[" + key + "]" : key - if (obj[key] instanceof Array) { - if(obj[key].length < 1) continue - out.push(serializeArray(obj[key], formatted)) - } - else if(typeof obj[key] === "object") { - if(JSON.stringify(obj[key]) === "{}") continue - out.push(serializeObject(obj[key], formatted)) - } - else out.push(encodeURIComponent(formatted) + "=" + encodeURIComponent(obj[key])) - } - return out.join("&") - } - function ajax(options) { if (options.dataType && options.dataType.toLowerCase() === "jsonp") { var callbackKey = "mithril_callback_" + new Date().getTime() + "_" + (Math.round(Math.random() * 1e16)).toString(36) @@ -857,7 +827,7 @@ Mithril = m = new function app(window, undefined) { + (options.url.indexOf("?") > 0 ? "&" : "?") + (options.callbackKey ? options.callbackKey : "callback") + "=" + callbackKey - + "&" + serializeObject(options.data || {}) + + "&" + buildQueryString(options.data || {}) window.document.body.appendChild(script) } else { From e8af4fd7b5c41e11eda57c3c6ba6528ec090a867 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sun, 14 Sep 2014 21:41:00 -0400 Subject: [PATCH 10/10] fix size in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 273d0822..0aada168 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Mithril is a client-side MVC framework - a tool to organize code in a way that i ### Light-weight -- Only 4kb gzipped, no dependencies +- Only 5kb gzipped, no dependencies - Small API, small learning curve ### Robust