From fc98b9fd3f46eaaffb4343beb3868cb86b473a8d Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 21 Jun 2012 12:09:26 +0800 Subject: [PATCH 01/43] updated VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6d7de6e..ae877a8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2 +1.0.2+ From 443469b8159432d9f8ab109a18dc2c89139a3306 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 21 Jun 2012 18:17:24 +0800 Subject: [PATCH 02/43] Better uri handling. Expose URI.Query and URI.Path --- src/util/uri.js | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/src/util/uri.js b/src/util/uri.js index d387e5c..8a9f763 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -11,6 +11,8 @@ define([ "compose" ], function URIModule(Compose) { var FUNCTION = Function; var ARRAY = Array; var ARRAY_PROTO = ARRAY.prototype; + var TYPEOF_OBJECT = typeof Object.prototype; + var TYPEOF_STRING = typeof String.prototype; var RE_URI = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?(?:([^?#]*)(?:\?([^#]*))?(?:#(.*))?)/; var PROTOCOL = "protocol"; @@ -37,34 +39,41 @@ define([ "compose" ], function URIModule(Compose) { // Prevent Compose from creating constructor property Compose.secure = true; - var Query = Compose(function Query(str) { - if (!str || str.length === 0) { - return; - } - + var Query = Compose(function Query(arg) { var self = this; var matches; - var key; + var key = NULL; var value; var re = /(?:&|^)([^&=]*)=?([^&]*)/g; - while (matches = re.exec(str)) { - key = matches[1]; + switch (typeof arg) { + case TYPEOF_OBJECT: + for (key in arg) { + self[key] = arg[key]; + } + break; - if (key in self) { - value = self[key]; + case TYPEOF_STRING: + while (matches = re.exec(str)) { + key = matches[1]; - if (value instanceof ARRAY) { - value[value.length] = matches[2]; + if (key in self) { + value = self[key]; + + if (value instanceof ARRAY) { + value[value.length] = matches[2]; + } + else { + self[key] = [ value, matches[2] ]; + } } else { - self[key] = [ value, matches[2] ]; + self[key] = matches[2]; } } - else { - self[key] = matches[2]; - } + break; } + }, { toString : function toString() { var self = this; @@ -152,7 +161,7 @@ define([ "compose" ], function URIModule(Compose) { }, { toString : function toString() { var self = this; - var uri = [ PROTOCOL , "://", AUTHORITY, PATH, "?", QUERY, "#", ANCHOR ]; + var uri = [ PROTOCOL , "://", AUTHORITY, "/", PATH, "?", QUERY, "#", ANCHOR ]; var i; var key; @@ -189,5 +198,8 @@ define([ "compose" ], function URIModule(Compose) { // Restore Compose.secure setting Compose.secure = SECURE; + URI.Path = Path; + URI.Query = Query; + return URI; }); \ No newline at end of file From 3f290ce81ae11d206da392baacd1d47e41162d33 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Fri, 29 Jun 2012 13:57:52 +0800 Subject: [PATCH 03/43] added dimensions service --- src/dimensions/service.js | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/dimensions/service.js diff --git a/src/dimensions/service.js b/src/dimensions/service.js new file mode 100644 index 0000000..3dc3ada --- /dev/null +++ b/src/dimensions/service.js @@ -0,0 +1,52 @@ +/*! + * TroopJS dimensions/service module + * @license TroopJS Copyright 2012, Mikael Karon + * Released under the MIT license. + */ +define([ "../component/service" ], function DimensionsServiceModule(Service) { + var DIMENSIONS = "dimensions"; + var $ELEMENT = "$element"; + + function onDimensions($event, w, h) { + $event.data.publish(DIMENSIONS, w, h); + } + + return Service.extend(function DimensionsService($element, dimensions) { + var self = this; + + self[$ELEMENT] = $element; + self[DIMENSIONS] = dimensions; + }, { + displayName : "core/dimensions/service", + + "sig/initialize" : function initialize(signal, deferred) { + var self = this; + + self[$ELEMENT].bind(DIMENSIONS + "." + self[DIMENSIONS], self, onDimensions); + + if (deferred) { + deferred.resolve(); + } + }, + + "sig/start" : function start(signal, deferred) { + var self = this; + + self[$ELEMENT].trigger("resize." + DIMENSIONS); + + if (deferred) { + deferred.resolve(); + } + }, + + "sig/finalize" : function finalize(signal, deferred) { + var self = this; + + self[$ELEMENT].unbind(DIMENSIONS + "." + self[DIMENSIONS], onDimensions); + + if (deferred) { + deferred.resolve(); + } + } + }); +}); \ No newline at end of file From 463af10f9dd0219478cec1e8718f2f71c2824711 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Mon, 2 Jul 2012 10:56:48 +0800 Subject: [PATCH 04/43] remove version from license --- src/util/uri.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/uri.js b/src/util/uri.js index 8a9f763..4d2ea27 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -3,7 +3,7 @@ * * parts of code from parseUri 1.2.2 Copyright Steven Levithan * - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "compose" ], function URIModule(Compose) { From db6aefa0e1d9b15bed6791f3af8a92dddd60ecfa Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Mon, 2 Jul 2012 10:58:30 +0800 Subject: [PATCH 05/43] splice more from path. closes gh-24 --- src/util/uri.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/uri.js b/src/util/uri.js index 4d2ea27..489ee5c 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -170,7 +170,7 @@ define([ "compose" ], function URIModule(Compose) { } if (!(PATH in self)) { - uri.splice(0, 1); + uri.splice(0, 2); } if (!(ANCHOR in self)) { From 81970ae7ab6769ad8c9721271891b1180751210e Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Mon, 2 Jul 2012 14:15:16 +0800 Subject: [PATCH 06/43] remove version from licence --- src/pubsub/hub.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pubsub/hub.js b/src/pubsub/hub.js index 51895ef..72d42f8 100644 --- a/src/pubsub/hub.js +++ b/src/pubsub/hub.js @@ -1,6 +1,6 @@ /*! * TroopJS pubsub/hub module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose, Component, Topic) { From 476b56e73ea1d76acde85a4c8fcaf0bff8cc2843 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Mon, 2 Jul 2012 14:15:31 +0800 Subject: [PATCH 07/43] fix operator priority (closes gh-23) --- src/pubsub/hub.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pubsub/hub.js b/src/pubsub/hub.js index 72d42f8..054ef65 100644 --- a/src/pubsub/hub.js +++ b/src/pubsub/hub.js @@ -181,7 +181,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose unsubscribe: { // Fast fail if we don't have subscribers - if (!topic in HANDLERS) { + if (!(topic in HANDLERS)) { break unsubscribe; } From 47795f06ad012306196361272046ef71e313e03e Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 3 Jul 2012 12:03:03 +0800 Subject: [PATCH 08/43] fix some constants (for better compression in the end) --- src/pubsub/hub.js | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/pubsub/hub.js b/src/pubsub/hub.js index 054ef65..dbe7423 100644 --- a/src/pubsub/hub.js +++ b/src/pubsub/hub.js @@ -4,12 +4,16 @@ * Released under the MIT license. */ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose, Component, Topic) { - var CONTEXT = {}; - var HANDLERS = {}; + var FUNCTION = Function; var MEMORY = "memory"; + var CONTEXT = "context"; + var CALLBACK = "callback"; + var LENGTH = "length"; var HEAD = "head"; var TAIL = "tail"; var NEXT = "next"; + var ROOT = {}; + var HANDLERS = {}; return Compose.create({ displayName: "core/pubsub/hub", @@ -25,7 +29,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose */ subscribe : function subscribe(topic /*, context, memory, callback, callback, ..*/) { var self = this; - var length = arguments.length; + var length = arguments[LENGTH]; var context = arguments[1]; var memory = arguments[2]; var callback = arguments[3]; @@ -36,27 +40,27 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose var tail; // No context or memory was supplied - if (context instanceof Function) { + if (context instanceof FUNCTION) { callback = context; memory = false; - context = CONTEXT; + context = ROOT; offset = 1; } // Only memory was supplied else if (context === true || context === false) { callback = memory; memory = context; - context = CONTEXT; + context = ROOT; offset = 2; } // Context was supplied, but not memory - else if (memory instanceof Function) { + else if (memory instanceof FUNCTION) { callback = memory; memory = false; offset = 2; } // All arguments were supplied - else if (callback instanceof Function){ + else if (callback instanceof FUNCTION){ offset = 3; } // Something is wrong, return fast @@ -101,9 +105,9 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose memory = handlers[MEMORY]; // Loop through handlers, optimize for arguments - if (memory.length > 0 ) while(handler) { + if (memory[LENGTH] > 0 ) while(handler) { // Apply handler callback - handler.callback.apply(handler.context, memory); + handler[CALLBACK].apply(handler[CONTEXT], memory); // Update handler handler = handler[NEXT]; @@ -111,7 +115,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Loop through handlers, optimize for no arguments else while(handler) { // Call handler callback - handler.callback.call(handler.context); + handler[CALLBACK].call(handler[CONTEXT]); // Update handler handler = handler[NEXT]; @@ -155,7 +159,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose * @returns self */ unsubscribe : function unsubscribe(topic /*, context, callback, callback, ..*/) { - var length = arguments.length; + var length = arguments[LENGTH]; var context = arguments[1]; var callback = arguments[2]; var offset; @@ -165,13 +169,13 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose var previous = null; // No context or memory was supplied - if (context instanceof Function) { + if (context instanceof FUNCTION) { callback = context; - context = CONTEXT; + context = ROOT; offset = 1; } // All arguments were supplied - else if (callback instanceof Function){ + else if (callback instanceof FUNCTION){ offset = 2; } // Something is wrong, return fast @@ -202,7 +206,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Loop through handlers do { // Check if this handler should be unlinked - if (handler.callback === callback && handler.context === context) { + if (handler[CALLBACK] === callback && handler[CONTEXT] === context) { // Is this the first handler if (handler === head) { // Re-link head and previous, then @@ -258,9 +262,9 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose handler = handlers[HEAD]; // Loop through handlers, optimize for arguments - if (arguments.length > 0) while(handler) { + if (arguments[LENGTH] > 0) while(handler) { // Apply handler callback - handler.callback.apply(handler.context, arguments); + handler[CALLBACK].apply(handler[CONTEXT], arguments); // Update handler handler = handler[NEXT]; @@ -268,14 +272,14 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Loop through handlers, optimize for no arguments else while(handler) { // Call handler callback - handler.callback.call(handler.context); + handler[CALLBACK].call(handler[CONTEXT]); // Update handler handler = handler[NEXT]; } } // No handlers - else if (arguments.length > 0){ + else if (arguments[LENGTH] > 0){ // Create handlers and store with topic HANDLERS[topic] = handlers = {}; From 6a503a2d903deb259c562f832cc5bbe942fbcaaf Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 3 Jul 2012 12:32:24 +0800 Subject: [PATCH 09/43] update comments --- src/pubsub/hub.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pubsub/hub.js b/src/pubsub/hub.js index dbe7423..4489746 100644 --- a/src/pubsub/hub.js +++ b/src/pubsub/hub.js @@ -80,7 +80,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose "context" : context }; - // Get last handler + // Get tail handler tail = TAIL in handlers // Have tail, update handlers.tail.next to point to handler ? handlers[TAIL][NEXT] = handler @@ -89,14 +89,14 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Iterate handlers from offset while (offset < length) { - // Set last -> last.next -> handler + // Set tail -> tail.next -> handler tail = tail[NEXT] = { "callback" : arguments[offset++], "context" : context }; } - // Set last handler + // Set tail handler handlers[TAIL] = tail; // Want memory and have memory @@ -132,7 +132,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Iterate handlers from offset while (offset < length) { - // Set last -> last.next -> handler + // Set tail -> tail.next -> handler tail = tail[NEXT] = { "callback" : arguments[offset++], "context" : context From efb34051a01537004ac851400a49a6e6b5171bae Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 3 Jul 2012 12:03:03 +0800 Subject: [PATCH 10/43] fix some constants (for better compression in the end) --- src/pubsub/hub.js | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/pubsub/hub.js b/src/pubsub/hub.js index 054ef65..dbe7423 100644 --- a/src/pubsub/hub.js +++ b/src/pubsub/hub.js @@ -4,12 +4,16 @@ * Released under the MIT license. */ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose, Component, Topic) { - var CONTEXT = {}; - var HANDLERS = {}; + var FUNCTION = Function; var MEMORY = "memory"; + var CONTEXT = "context"; + var CALLBACK = "callback"; + var LENGTH = "length"; var HEAD = "head"; var TAIL = "tail"; var NEXT = "next"; + var ROOT = {}; + var HANDLERS = {}; return Compose.create({ displayName: "core/pubsub/hub", @@ -25,7 +29,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose */ subscribe : function subscribe(topic /*, context, memory, callback, callback, ..*/) { var self = this; - var length = arguments.length; + var length = arguments[LENGTH]; var context = arguments[1]; var memory = arguments[2]; var callback = arguments[3]; @@ -36,27 +40,27 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose var tail; // No context or memory was supplied - if (context instanceof Function) { + if (context instanceof FUNCTION) { callback = context; memory = false; - context = CONTEXT; + context = ROOT; offset = 1; } // Only memory was supplied else if (context === true || context === false) { callback = memory; memory = context; - context = CONTEXT; + context = ROOT; offset = 2; } // Context was supplied, but not memory - else if (memory instanceof Function) { + else if (memory instanceof FUNCTION) { callback = memory; memory = false; offset = 2; } // All arguments were supplied - else if (callback instanceof Function){ + else if (callback instanceof FUNCTION){ offset = 3; } // Something is wrong, return fast @@ -101,9 +105,9 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose memory = handlers[MEMORY]; // Loop through handlers, optimize for arguments - if (memory.length > 0 ) while(handler) { + if (memory[LENGTH] > 0 ) while(handler) { // Apply handler callback - handler.callback.apply(handler.context, memory); + handler[CALLBACK].apply(handler[CONTEXT], memory); // Update handler handler = handler[NEXT]; @@ -111,7 +115,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Loop through handlers, optimize for no arguments else while(handler) { // Call handler callback - handler.callback.call(handler.context); + handler[CALLBACK].call(handler[CONTEXT]); // Update handler handler = handler[NEXT]; @@ -155,7 +159,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose * @returns self */ unsubscribe : function unsubscribe(topic /*, context, callback, callback, ..*/) { - var length = arguments.length; + var length = arguments[LENGTH]; var context = arguments[1]; var callback = arguments[2]; var offset; @@ -165,13 +169,13 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose var previous = null; // No context or memory was supplied - if (context instanceof Function) { + if (context instanceof FUNCTION) { callback = context; - context = CONTEXT; + context = ROOT; offset = 1; } // All arguments were supplied - else if (callback instanceof Function){ + else if (callback instanceof FUNCTION){ offset = 2; } // Something is wrong, return fast @@ -202,7 +206,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Loop through handlers do { // Check if this handler should be unlinked - if (handler.callback === callback && handler.context === context) { + if (handler[CALLBACK] === callback && handler[CONTEXT] === context) { // Is this the first handler if (handler === head) { // Re-link head and previous, then @@ -258,9 +262,9 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose handler = handlers[HEAD]; // Loop through handlers, optimize for arguments - if (arguments.length > 0) while(handler) { + if (arguments[LENGTH] > 0) while(handler) { // Apply handler callback - handler.callback.apply(handler.context, arguments); + handler[CALLBACK].apply(handler[CONTEXT], arguments); // Update handler handler = handler[NEXT]; @@ -268,14 +272,14 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Loop through handlers, optimize for no arguments else while(handler) { // Call handler callback - handler.callback.call(handler.context); + handler[CALLBACK].call(handler[CONTEXT]); // Update handler handler = handler[NEXT]; } } // No handlers - else if (arguments.length > 0){ + else if (arguments[LENGTH] > 0){ // Create handlers and store with topic HANDLERS[topic] = handlers = {}; From e298381303330157caef3fcb297666d03d358dd8 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 3 Jul 2012 16:36:51 +0800 Subject: [PATCH 11/43] added support for marking handled handlers (to prevent republish after subscribe) closes gh-25 --- src/pubsub/hub.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/pubsub/hub.js b/src/pubsub/hub.js index dbe7423..9a9563a 100644 --- a/src/pubsub/hub.js +++ b/src/pubsub/hub.js @@ -12,8 +12,10 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose var HEAD = "head"; var TAIL = "tail"; var NEXT = "next"; + var HANDLED = "handled"; var ROOT = {}; var HANDLERS = {}; + var COUNT = 0; return Compose.create({ displayName: "core/pubsub/hub", @@ -36,6 +38,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose var offset; var handlers; var handler; + var handled; var head; var tail; @@ -104,8 +107,20 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Get memory memory = handlers[MEMORY]; + // Get handled + handled = memory[HANDLED]; + // Loop through handlers, optimize for arguments if (memory[LENGTH] > 0 ) while(handler) { + // Skip to next handler if this handler has already been handled + if (handler[HANDLED] === handled) { + handler = handler[NEXT]; + continue; + } + + // Store handled + handler[HANDLED] = handled; + // Apply handler callback handler[CALLBACK].apply(handler[CONTEXT], memory); @@ -114,6 +129,15 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose } // Loop through handlers, optimize for no arguments else while(handler) { + // Skip to next handler if this handler has already been handled + if (handler[HANDLED] === handled) { + handler = handler[NEXT]; + continue; + } + + // Store handled + handler[HANDLED] = handled; + // Call handler callback handler[CALLBACK].call(handler[CONTEXT]); @@ -250,6 +274,9 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose var handlers; var handler; + // Store handled + var handled = arguments[HANDLED] = COUNT++; + // Have handlers if (topic in HANDLERS) { // Get handlers @@ -263,6 +290,15 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Loop through handlers, optimize for arguments if (arguments[LENGTH] > 0) while(handler) { + // Skip to next handler if this handler has already been handled + if (handler[HANDLED] === handled) { + handler = handler[NEXT]; + continue; + } + + // Update handled + handler[HANDLED] = handled; + // Apply handler callback handler[CALLBACK].apply(handler[CONTEXT], arguments); @@ -271,6 +307,15 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose } // Loop through handlers, optimize for no arguments else while(handler) { + // Skip to next handler if this handler has already been handled + if (handler[HANDLED] === handled) { + handler = handler[NEXT]; + continue; + } + + // Update handled + handler[HANDLED] = handled; + // Call handler callback handler[CALLBACK].call(handler[CONTEXT]); From 6648eec9f3f20d4cb17a47d1712f1a95ce1b0418 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Wed, 4 Jul 2012 18:05:48 +0800 Subject: [PATCH 12/43] filter unique publishers it topic.trace. closes gh-28 --- src/pubsub/topic.js | 25 +++++++++++++++++-------- src/util/unique.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/util/unique.js diff --git a/src/pubsub/topic.js b/src/pubsub/topic.js index fc60e94..fca9908 100644 --- a/src/pubsub/topic.js +++ b/src/pubsub/topic.js @@ -3,8 +3,13 @@ * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon * Released under the MIT license. */ -define([ "../component/base" ], function TopicModule(Component) { - var ARRAY = Array; +define([ "../component/base", "../util/unique" ], function TopicModule(Component, unique) { + var TOSTRING = Object.prototype.toString; + var TOSTRING_ARRAY = TOSTRING.call(Array.prototype); + + function comparator (a, b) { + return a.publisherInstanceCount === b.publisherInstanceCount; + } return Component.extend(function Topic(topic, publisher, parent) { var self = this; @@ -12,6 +17,7 @@ define([ "../component/base" ], function TopicModule(Component) { self.topic = topic; self.publisher = publisher; self.parent = parent; + self.publisherInstanceCount = publisher.instanceCount; }, { displayName : "core/pubsub/topic", @@ -34,19 +40,22 @@ define([ "../component/base" ], function TopicModule(Component) { var item; var stack = ""; var i; + var u; var iMax; while (current) { - if (current.constructor === ARRAY) { - for (i = 0, iMax = current.length; i < iMax; i++) { - item = current[i]; + if (TOSTRING.call(current) === TOSTRING_ARRAY) { + u = unique.call(current, comparator); + + for (i = 0, iMax = u.length; i < iMax; i++) { + item = u[i]; - current[i] = item.constructor === constructor + u[i] = item.constructor === constructor ? item.trace() - : item; + : item.topic; } - stack += current.join(","); + stack += u.join(","); break; } diff --git a/src/util/unique.js b/src/util/unique.js new file mode 100644 index 0000000..b5c1eae --- /dev/null +++ b/src/util/unique.js @@ -0,0 +1,30 @@ +/*! + * TroopJS util/unique component + * @license TroopJS Copyright 2012, Mikael Karon + * Released under the MIT license. + */ +define(function UniqueModule() { + return function unique(callback) { + var self = this; + var length = self.length; + var result = []; + var value; + var i; + var j; + var k; + + add: for (i = j = k = 0; i < length; i++, j = 0) { + value = self[i]; + + while(j < k) { + if (callback.call(self, value, result[j++]) === true) { + continue add; + } + } + + result[k++] = value; + } + + return result; + }; +}); \ No newline at end of file From 966ae2039ed820f1b8dde9e7a27142b6155c16f7 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Wed, 11 Jul 2012 17:49:05 +0800 Subject: [PATCH 13/43] more robust implementation for deferred detection. see troopjs/troopjs-core#34 --- src/component/widget.js | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/component/widget.js b/src/component/widget.js index 1600773..a307d3b 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -66,40 +66,36 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge var $element = self[$ELEMENT]; var arg = arguments; - // Get contents from first argument + // Shift contents from first argument var contents = SHIFT.call(arg); - // Get arg length - var argc = arg.length; + // Assume deferred is the last argument + var deferred = arg[arg.length]; - // Check if the last argument looks like a deferred, and in that case set it - var deferred = argc > 0 && arg[argc - 1][THEN] instanceof FUNCTION - ? POP.call(arg) - : UNDEFINED; - - if (deferred){ - deferred.notifyWith(this, ['beforeRender']); - } - - // Call render with contents (or result of contents if it's a function) - $fn.call($element, contents instanceof FUNCTION ? contents.apply(self, arg) : contents); - - if (deferred){ - deferred.notifyWith(this, ['afterRender']); + // If deferred not a true Deferred, make it so + if (deferred === UNDEFINED || !(deferred[THEN] instanceof FUNCTION)) { + deferred = Deferred(); } // Defer render (as weaving it may need to load async) Deferred(function deferredRender(dfdRender) { - // After render is complete, trigger REFRESH with woven components + // After render is complete, trigger REFRESH with woven components. Add this here to make sure it's the first done hadler dfdRender.done(function renderDone() { $element.trigger(REFRESH, arguments); }); // Link deferred - if (deferred) { - dfdRender.then(deferred.resolve, deferred.reject, deferred.notify); - } + dfdRender.then(deferred.resolve, deferred.reject, deferred.notify); + + // Notify that we're about to render + dfdRender.notify([ "beforeRender" ]); + + // Call render with contents (or result of contents if it's a function) + $fn.call($element, contents instanceof FUNCTION ? contents.apply(self, arg) : contents); + + // Notify that we're rendered + dfdRender.notify([ "afterRender" ]); // Weave element $element.find(ATTR_WEAVE).weave(dfdRender); From b75fbd50a5c811ee056ff59921fc297b870bc0f9 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Wed, 11 Jul 2012 17:50:02 +0800 Subject: [PATCH 14/43] add notify to deferred chain --- src/component/widget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/component/widget.js b/src/component/widget.js index a307d3b..1144647 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -317,9 +317,9 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge dfd.resolve(contents); }, 0); - // If a deferred was passed, add resolve/reject + // If a deferred was passed, add resolve/reject/notify if (deferred) { - dfd.then(deferred.resolve, deferred.reject); + dfd.then(deferred.resolve, deferred.reject, deferred.notify); } }); From 0ffb1d1a68cde0b6d819d9878ba198f73fb76225 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Wed, 11 Jul 2012 23:24:23 +0800 Subject: [PATCH 15/43] add sandbox widget. closes troopjs/troopjs-core#35 --- src/component/sandbox.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/component/sandbox.js diff --git a/src/component/sandbox.js b/src/component/sandbox.js new file mode 100644 index 0000000..40983a1 --- /dev/null +++ b/src/component/sandbox.js @@ -0,0 +1,30 @@ +/*! + * TroopJS sandbox component + * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * Released under the MIT license. + */ +define( [ "./widget", "jquery" ], function SandboxModule(Widget, $) { + var $ELEMENT = "$element"; + var _$ELEMENT = "_" + $ELEMENT; + + return Widget.extend({ + "sig/initialize" : function onInitialize(signal, deferred) { + var self = this; + + // Store ref to current $element + var $element = self[_$ELEMENT] = self[$ELEMENT]; + + // Set $element to iframe document element + self[$ELEMENT] = $($element.get(0).contentDocument); + + if (deferred) { + deferred.resolve(); + } + }, + + "sig/start" : function onStart(signal, deferred) { + // Forward weave + this.weave(deferred); + } + }); +}); From 08653f34f908bb123b8fe97720fb45a81d60b319 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 12 Jul 2012 00:01:37 +0800 Subject: [PATCH 16/43] fix for IE --- src/component/sandbox.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/component/sandbox.js b/src/component/sandbox.js index 40983a1..dbc7dc7 100644 --- a/src/component/sandbox.js +++ b/src/component/sandbox.js @@ -14,8 +14,11 @@ define( [ "./widget", "jquery" ], function SandboxModule(Widget, $) { // Store ref to current $element var $element = self[_$ELEMENT] = self[$ELEMENT]; + // Get the contentWindow + var contentWindow = $element.get(0).contentWindow; + // Set $element to iframe document element - self[$ELEMENT] = $($element.get(0).contentDocument); + self[$ELEMENT] = $(contentWindow.ownerDocument || contentWindow.document); if (deferred) { deferred.resolve(); From 4d82fb62366650f81d8f322e1634231bfbe2d20e Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 12 Jul 2012 11:03:13 +0800 Subject: [PATCH 17/43] move sandbox to widget forward sig/stop (as unweave) --- src/{component => widget}/sandbox.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) rename src/{component => widget}/sandbox.js (70%) diff --git a/src/component/sandbox.js b/src/widget/sandbox.js similarity index 70% rename from src/component/sandbox.js rename to src/widget/sandbox.js index dbc7dc7..3c52d63 100644 --- a/src/component/sandbox.js +++ b/src/widget/sandbox.js @@ -1,9 +1,9 @@ /*! - * TroopJS sandbox component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * TroopJS widget/sandbox component + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ -define( [ "./widget", "jquery" ], function SandboxModule(Widget, $) { +define( [ "../component/widget", "jquery" ], function SandboxModule(Widget, $) { var $ELEMENT = "$element"; var _$ELEMENT = "_" + $ELEMENT; @@ -26,8 +26,11 @@ define( [ "./widget", "jquery" ], function SandboxModule(Widget, $) { }, "sig/start" : function onStart(signal, deferred) { - // Forward weave this.weave(deferred); + }, + + "sig/stop" : function onStop(signal, deferred) { + this.unweave(deferred); } }); }); From f1ea2638507caa715e915876db7ad4b0fbd1be1e Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 12 Jul 2012 11:04:31 +0800 Subject: [PATCH 18/43] remove unused var --- src/component/widget.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/component/widget.js b/src/component/widget.js index 1144647..5dddd1d 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -13,7 +13,6 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge var ARRAY_PROTO = Array.prototype; var SHIFT = ARRAY_PROTO.shift; var UNSHIFT = ARRAY_PROTO.unshift; - var POP = ARRAY_PROTO.pop; var $TRIGGER = $.fn.trigger; var $ONE = $.fn.one; var $BIND = $.fn.bind; From e80ad19c0a9877e737dd22b39bd3d530b98da5bb Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 12 Jul 2012 11:04:45 +0800 Subject: [PATCH 19/43] send deferred to unweave --- src/component/widget.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/component/widget.js b/src/component/widget.js index 5dddd1d..7514f5f 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -197,12 +197,13 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge /** * Unweaves all children of $element _and_ self + * @param deferred (Deferred) Deferred (optional) * @returns self */ - unweave : function unweave() { + unweave : function unweave(deferred) { var self = this; - self[$ELEMENT].find(ATTR_WOVEN).andSelf().unweave(); + self[$ELEMENT].find(ATTR_WOVEN).andSelf().unweave(deferred); return this; }, From a9e4831fec9ef41cd837320527a12b29ede4efac Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 12 Jul 2012 11:05:13 +0800 Subject: [PATCH 20/43] update licence save some bytes as signals should not return --- src/widget/application.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/widget/application.js b/src/widget/application.js index e22b499..12384c9 100644 --- a/src/widget/application.js +++ b/src/widget/application.js @@ -1,6 +1,6 @@ /*! * TroopJS widget/application component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "../component/widget", "../util/deferred" ], function ApplicationModule(Widget, Deferred) { @@ -8,19 +8,11 @@ define([ "../component/widget", "../util/deferred" ], function ApplicationModule displayName : "core/widget/application", "sig/start" : function start(signal, deferred) { - var self = this; - - self.weave(deferred); - - return self; + this.weave(deferred); }, "sig/stop" : function stop(signal, deferred) { - var self = this; - - self.unweave(deferred); - - return self; + this.unweave(deferred); } }); }); \ No newline at end of file From e59f78c89b9389b3f0fc820dd3ee2784cdb53eba Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 12 Jul 2012 13:38:38 +0800 Subject: [PATCH 21/43] fix wrong arg access --- src/component/widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/widget.js b/src/component/widget.js index 7514f5f..2025543 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -69,7 +69,7 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge var contents = SHIFT.call(arg); // Assume deferred is the last argument - var deferred = arg[arg.length]; + var deferred = arg[arg.length - 1]; // If deferred not a true Deferred, make it so if (deferred === UNDEFINED || !(deferred[THEN] instanceof FUNCTION)) { From d29658b53270f138878198804325483e9fa876e9 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 12 Jul 2012 15:56:05 +0800 Subject: [PATCH 22/43] refactored start/stop deferred --- src/component/gadget.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/component/gadget.js b/src/component/gadget.js index 732aa74..ed31985 100644 --- a/src/component/gadget.js +++ b/src/component/gadget.js @@ -222,18 +222,18 @@ define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function Ga start : function start(deferred) { var self = this; + deferred = deferred || Deferred(); + Deferred(function deferredStart(dfdStart) { + dfdStart.then(deferred.resolve, deferred.reject, deferred.notify); + Deferred(function deferredInitialize(dfdInitialize) { + dfdInitialize.then(function doneInitialize() { + self.signal("start", dfdStart); + }, dfdStart.reject, dfdStart.notify); + self.signal("initialize", dfdInitialize); - }) - .done(function doneInitialize() { - self.signal("start", dfdStart); - }) - .fail(dfdStart.reject); - - if (deferred) { - dfdStart.then(deferred.resolve, deferred.reject); - } + }); }); return self; @@ -242,18 +242,18 @@ define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function Ga stop : function stop(deferred) { var self = this; + deferred = deferred || Deferred(); + Deferred(function deferredFinalize(dfdFinalize) { + dfdFinalize.then(deferred.resolve, deferred.reject, deferred.notify); + Deferred(function deferredStop(dfdStop) { - self.signal("stop", dfdStop); - }) - .done(function doneStop() { - self.signal("finalize", dfdFinalize); - }) - .fail(dfdFinalize.reject); - - if (deferred) { - dfdFinalize.then(deferred.resolve, deferred.reject); - } + dfdStop.then(function doneStop() { + self.signal("finalize", dfdStop); + }, dfdFinalize.reject, dfdFinalize.notify); + + self.signal("stop", dfdFinalize); + }); }); return self; From 5b4fd740698ea4f98937c561f1363e74804bd529 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 12 Jul 2012 15:56:25 +0800 Subject: [PATCH 23/43] fix before/afterRender --- src/component/widget.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/component/widget.js b/src/component/widget.js index 2025543..17af40b 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -79,22 +79,23 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge // Defer render (as weaving it may need to load async) Deferred(function deferredRender(dfdRender) { - // After render is complete, trigger REFRESH with woven components. Add this here to make sure it's the first done hadler - dfdRender.done(function renderDone() { + // Link deferred + dfdRender.then(function renderDone() { + // Trigger refresh $element.trigger(REFRESH, arguments); - }); - // Link deferred - dfdRender.then(deferred.resolve, deferred.reject, deferred.notify); + // Resolve outer deferred + deferred.resolve(); + }, deferred.reject, deferred.notify); // Notify that we're about to render - dfdRender.notify([ "beforeRender" ]); + dfdRender.notify("beforeRender", self); // Call render with contents (or result of contents if it's a function) $fn.call($element, contents instanceof FUNCTION ? contents.apply(self, arg) : contents); // Notify that we're rendered - dfdRender.notify([ "afterRender" ]); + dfdRender.notify("afterRender", self); // Weave element $element.find(ATTR_WEAVE).weave(dfdRender); From 6d34ad2eb5847f7994398c86e20cf5b75c0267bc Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Fri, 13 Jul 2012 09:38:49 +0800 Subject: [PATCH 24/43] deferred related cleanup --- src/component/widget.js | 15 ++++---- src/remote/ajax.js | 2 +- src/widget/placeholder.js | 72 ++++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 46 deletions(-) diff --git a/src/component/widget.js b/src/component/widget.js index 17af40b..50578d6 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -295,8 +295,14 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge empty : function empty(deferred) { var self = this; + // Ensure we have deferred + deferred = deferred || Deferred(); + // Create deferred for emptying - Deferred(function emptyDeferred(dfd) { + Deferred(function emptyDeferred(dfdEmpty) { + // Link deferred + dfdEmpty.then(deferred.resolve, deferred.reject, deferred.notify); + // Get element var $element = self[$ELEMENT]; @@ -315,13 +321,8 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge $contents.remove(); // Resolve deferred - dfd.resolve(contents); + dfdEmpty.resolve(contents); }, 0); - - // If a deferred was passed, add resolve/reject/notify - if (deferred) { - dfd.then(deferred.resolve, deferred.reject, deferred.notify); - } }); return self; diff --git a/src/remote/ajax.js b/src/remote/ajax.js index 47779aa..cbdb390 100644 --- a/src/remote/ajax.js +++ b/src/remote/ajax.js @@ -14,7 +14,7 @@ define([ "../component/service", "../pubsub/topic", "jquery", "../util/merge" ], "x-request-id": new Date().getTime(), "x-components": topic instanceof Topic ? topic.trace() : topic } - }, settings)).then(deferred.resolve, deferred.reject); + }, settings)).then(deferred.resolve, deferred.reject, deferred.notify); } }); }); \ No newline at end of file diff --git a/src/widget/placeholder.js b/src/widget/placeholder.js index 2748003..b89847e 100644 --- a/src/widget/placeholder.js +++ b/src/widget/placeholder.js @@ -6,9 +6,6 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholderModule(Widget, Deferred) { var UNDEFINED = undefined; var FUNCTION = Function; - var ARRAY = Array; - var ARRAY_PROTO = ARRAY.prototype; - var POP = ARRAY_PROTO.pop; var HOLDING = "holding"; var DATA_HOLDING = "data-" + HOLDING; var $ELEMENT = "$element"; @@ -18,14 +15,16 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholder function release(/* arg, arg, arg, deferred*/) { var self = this; var arg = arguments; - var argc = arg.length; - // Check if the last argument looks like a deferred, and in that case set it - var deferred = argc > 0 && arg[argc - 1][THEN] instanceof FUNCTION - ? POP.call(arg) - : UNDEFINED; + // Assume deferred is the last argument + var deferred = arg[arg.length - 1]; - Deferred(function deferredRelease(dfd) { + // If deferred not a true Deferred, make it so + if (deferred === UNDEFINED || !(deferred[THEN] instanceof FUNCTION)) { + deferred = Deferred(); + } + + Deferred(function deferredRelease(dfdRelease) { var i; var iMax; var name; @@ -33,17 +32,19 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholder // We're already holding something, resolve with cache if (HOLDING in self) { - dfd.resolve(self[HOLDING]); + dfdRelease + .done(deferred.resolve) + .resolve(self[HOLDING]); } else { // Add done handler to release - dfd.done(function doneRelease(widget) { + dfdRelease.then([ function doneRelease(widget) { // Set DATA_HOLDING attribute self[$ELEMENT].attr(DATA_HOLDING, widget); // Store widget self[HOLDING] = widget; - }); + }, deferred.resolve ], deferred.reject, deferred.notify); // Get widget name name = self[TARGET]; @@ -58,24 +59,22 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholder // Require widget by name require([ name ], function required(Widget) { - // Resolve with constructed, bound and initialized instance - var widget = Widget - .apply(Widget, argv); - - Deferred(function deferredStart(dfdStart) { - widget.start(dfdStart); - }) - .done(function doneStarted() { - dfd.resolve(widget); - }) - .fail(dfd.reject); + // Defer require + Deferred(function deferredStart(dfdRequire) { + // Constructed and initialized instance + var widget = Widget + .apply(Widget, argv); + + // Link deferred + dfdRequire.then(function doneStart() { + dfdRelease.resolve(widget); + }, dfdRelease.reject, dfdRelease.notify); + + // Start + widget.start(dfdRequire); + }); }); } - - // Link deferred - if (deferred) { - dfd.then(deferred.resolve, deferred.reject); - } }); return self; @@ -84,9 +83,14 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholder function hold(deferred) { var self = this; + deferred = deferred || Deferred(); + Deferred(function deferredHold(dfdHold) { var widget; + // Link deferred + dfdHold.then(deferred.resolve, deferred.reject, deferred.notify); + // Check that we are holding if (HOLDING in self) { // Get what we're holding @@ -98,20 +102,12 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholder // Remove DATA_HOLDING attribute self[$ELEMENT].removeAttr(DATA_HOLDING); - // Deferred stop - Deferred(function deferredStop(dfdStop) { - widget.stop(dfdStop); - }) - .then(dfdHold.resolve, dfdHold.reject); + // Stop + widget.stop(dfdHold); } else { dfdHold.resolve(); } - - // Link deferred - if (deferred) { - dfdHold.then(deferred.resolve, deferred.reject); - } }); return self; From 5a6437b0fab4f23037f574ee94f325b718412fed Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Fri, 13 Jul 2012 09:45:25 +0800 Subject: [PATCH 25/43] fix headers --- src/component/base.js | 2 +- src/component/gadget.js | 2 +- src/component/service.js | 2 +- src/component/widget.js | 2 +- src/pubsub/topic.js | 2 +- src/remote/ajax.js | 2 +- src/route/placeholder.js | 2 +- src/route/router.js | 2 +- src/store/base.js | 2 +- src/store/local.js | 2 +- src/store/session.js | 2 +- src/util/callbacks.js | 4 ++-- src/util/deferred.js | 4 ++-- src/util/each.js | 4 ++-- src/util/grep.js | 4 ++-- src/util/merge.js | 2 +- src/util/tr.js | 2 +- src/util/when.js | 4 ++-- src/widget/placeholder.js | 2 +- 19 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/component/base.js b/src/component/base.js index a72c81a..c432e1b 100644 --- a/src/component/base.js +++ b/src/component/base.js @@ -1,6 +1,6 @@ /*! * TroopJS base component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ /** diff --git a/src/component/gadget.js b/src/component/gadget.js index ed31985..c445c3c 100644 --- a/src/component/gadget.js +++ b/src/component/gadget.js @@ -1,6 +1,6 @@ /*! * TroopJS gadget component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ /** diff --git a/src/component/service.js b/src/component/service.js index 70e3166..4bacbe7 100644 --- a/src/component/service.js +++ b/src/component/service.js @@ -1,6 +1,6 @@ /*! * TroopJS service component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "./gadget" ], function ServiceModule(Gadget) { diff --git a/src/component/widget.js b/src/component/widget.js index 50578d6..2fd19ab 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -1,6 +1,6 @@ /*! * TroopJS widget component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ /** diff --git a/src/pubsub/topic.js b/src/pubsub/topic.js index fca9908..1612b94 100644 --- a/src/pubsub/topic.js +++ b/src/pubsub/topic.js @@ -1,6 +1,6 @@ /*! * TroopJS pubsub/topic module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "../component/base", "../util/unique" ], function TopicModule(Component, unique) { diff --git a/src/remote/ajax.js b/src/remote/ajax.js index cbdb390..16faa4e 100644 --- a/src/remote/ajax.js +++ b/src/remote/ajax.js @@ -1,6 +1,6 @@ /*! * TroopJS remote/ajax module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "../component/service", "../pubsub/topic", "jquery", "../util/merge" ], function AjaxModule(Service, Topic, $, merge) { diff --git a/src/route/placeholder.js b/src/route/placeholder.js index 747b457..cfaed11 100644 --- a/src/route/placeholder.js +++ b/src/route/placeholder.js @@ -1,6 +1,6 @@ /*! * TroopJS route/placeholder module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "../widget/placeholder" ], function RoutePlaceholderModule(Placeholder) { diff --git a/src/route/router.js b/src/route/router.js index b33fcd0..504932d 100644 --- a/src/route/router.js +++ b/src/route/router.js @@ -1,6 +1,6 @@ /*! * TroopJS route/router module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "../component/service", "../util/uri" ], function RouterModule(Service, URI) { diff --git a/src/store/base.js b/src/store/base.js index 7c63dd4..fb17a0f 100644 --- a/src/store/base.js +++ b/src/store/base.js @@ -1,6 +1,6 @@ /*! * TroopJS store/base module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "compose", "../component/gadget" ], function StoreModule(Compose, Gadget) { diff --git a/src/store/local.js b/src/store/local.js index 3b26ef4..d8657b1 100644 --- a/src/store/local.js +++ b/src/store/local.js @@ -1,6 +1,6 @@ /*! * TroopJS store/local module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "compose", "./base" ], function StoreLocalModule(Compose, Store) { diff --git a/src/store/session.js b/src/store/session.js index cf28ba7..bb8bf68 100644 --- a/src/store/session.js +++ b/src/store/session.js @@ -1,6 +1,6 @@ /*! * TroopJS store/session module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "compose", "./base" ], function StoreSessionModule(Compose, Store) { diff --git a/src/util/callbacks.js b/src/util/callbacks.js index cdb15cf..6eb941a 100644 --- a/src/util/callbacks.js +++ b/src/util/callbacks.js @@ -1,6 +1,6 @@ /*! - * TroopJS callbacks component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * TroopJS util/callbacks component + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "jquery" ], function CallbacksModule($) { diff --git a/src/util/deferred.js b/src/util/deferred.js index 8401f3e..9e7ad86 100644 --- a/src/util/deferred.js +++ b/src/util/deferred.js @@ -1,6 +1,6 @@ /*! - * TroopJS deferred component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * TroopJS util/deferred component + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "jquery" ], function DeferredModule($) { diff --git a/src/util/each.js b/src/util/each.js index d99cd45..b275618 100644 --- a/src/util/each.js +++ b/src/util/each.js @@ -1,6 +1,6 @@ /*! - * TroopJS each component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * TroopJS util/each component + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "jquery" ], function EachModule($) { diff --git a/src/util/grep.js b/src/util/grep.js index 9bf2499..771d9cf 100644 --- a/src/util/grep.js +++ b/src/util/grep.js @@ -1,6 +1,6 @@ /*! - * TroopJS grep component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * TroopJS util/grep component + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "jquery" ], function GrepModule($) { diff --git a/src/util/merge.js b/src/util/merge.js index cad1afc..ef0be66 100644 --- a/src/util/merge.js +++ b/src/util/merge.js @@ -1,6 +1,6 @@ /*! * TroopJS util/merge module - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define(function MergeModule() { diff --git a/src/util/tr.js b/src/util/tr.js index ae54159..67c31dc 100644 --- a/src/util/tr.js +++ b/src/util/tr.js @@ -1,6 +1,6 @@ /*! * TroopJS util/tr component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define(function TrModule() { diff --git a/src/util/when.js b/src/util/when.js index cfa2f34..aa148a8 100644 --- a/src/util/when.js +++ b/src/util/when.js @@ -1,6 +1,6 @@ /*! - * TroopJS when component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * TroopJS util/when component + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "jquery" ], function WhenModule($) { diff --git a/src/widget/placeholder.js b/src/widget/placeholder.js index b89847e..8bb0516 100644 --- a/src/widget/placeholder.js +++ b/src/widget/placeholder.js @@ -1,6 +1,6 @@ /*! * TroopJS widget/placeholder component - * @license TroopJS 0.0.1 Copyright 2012, Mikael Karon + * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholderModule(Widget, Deferred) { From 99b5b17fb71d93b7c7f70c96197177ea64f7adab Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Fri, 13 Jul 2012 10:16:21 +0800 Subject: [PATCH 26/43] fix regression where deferred is not removed from arg list --- src/widget/placeholder.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/widget/placeholder.js b/src/widget/placeholder.js index 8bb0516..854c567 100644 --- a/src/widget/placeholder.js +++ b/src/widget/placeholder.js @@ -4,8 +4,8 @@ * Released under the MIT license. */ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholderModule(Widget, Deferred) { - var UNDEFINED = undefined; var FUNCTION = Function; + var POP = Array.prototype.pop; var HOLDING = "holding"; var DATA_HOLDING = "data-" + HOLDING; var $ELEMENT = "$element"; @@ -16,13 +16,10 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholder var self = this; var arg = arguments; - // Assume deferred is the last argument - var deferred = arg[arg.length - 1]; - // If deferred not a true Deferred, make it so - if (deferred === UNDEFINED || !(deferred[THEN] instanceof FUNCTION)) { - deferred = Deferred(); - } + var deferred = arg[arg.length - 1][THEN] instanceof FUNCTION + ? POP.call(arg) + : $.Deferred(); Deferred(function deferredRelease(dfdRelease) { var i; From e365399ccd02260b0408cf1e8762e25cb07cf378 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Fri, 13 Jul 2012 10:19:37 +0800 Subject: [PATCH 27/43] quite the `$` --- src/widget/placeholder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/placeholder.js b/src/widget/placeholder.js index 854c567..b87ec5b 100644 --- a/src/widget/placeholder.js +++ b/src/widget/placeholder.js @@ -19,7 +19,7 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholder // If deferred not a true Deferred, make it so var deferred = arg[arg.length - 1][THEN] instanceof FUNCTION ? POP.call(arg) - : $.Deferred(); + : Deferred(); Deferred(function deferredRelease(dfdRelease) { var i; From ce621f77d368471a774bb02963bca78bd026f3ba Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Fri, 13 Jul 2012 10:36:31 +0800 Subject: [PATCH 28/43] fix regression where deferred is not removed from arg list --- src/widget/placeholder.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/widget/placeholder.js b/src/widget/placeholder.js index b87ec5b..4839613 100644 --- a/src/widget/placeholder.js +++ b/src/widget/placeholder.js @@ -15,9 +15,10 @@ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholder function release(/* arg, arg, arg, deferred*/) { var self = this; var arg = arguments; + var argc = arg.length; // If deferred not a true Deferred, make it so - var deferred = arg[arg.length - 1][THEN] instanceof FUNCTION + var deferred = argc > 0 && arg[argc - 1][THEN] instanceof FUNCTION ? POP.call(arg) : Deferred(); From 5524f0b21299451adcea8972d0e20febe66e2fc4 Mon Sep 17 00:00:00 2001 From: zjhiphop Date: Tue, 17 Jul 2012 11:42:18 +0800 Subject: [PATCH 29/43] fix widget stoped but not unsubscribe topics with the widget issue --- src/component/gadget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/component/gadget.js b/src/component/gadget.js index c445c3c..ba621b0 100644 --- a/src/component/gadget.js +++ b/src/component/gadget.js @@ -249,10 +249,10 @@ define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function Ga Deferred(function deferredStop(dfdStop) { dfdStop.then(function doneStop() { - self.signal("finalize", dfdStop); + self.signal("finalize", dfdFinalize); }, dfdFinalize.reject, dfdFinalize.notify); - self.signal("stop", dfdFinalize); + self.signal("stop", dfdStop); }); }); From ee4b33d731d800ba3d7394b44ae2d7f587f19855 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Mon, 23 Jul 2012 17:08:39 +0800 Subject: [PATCH 30/43] added test for util/uri udate util/uri to pass test --- src/util/uri.js | 38 ++- test/util/uri.js | 850 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 870 insertions(+), 18 deletions(-) create mode 100644 test/util/uri.js diff --git a/src/util/uri.js b/src/util/uri.js index 489ee5c..da3cc4b 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -8,11 +8,13 @@ */ define([ "compose" ], function URIModule(Compose) { var NULL = null; - var FUNCTION = Function; - var ARRAY = Array; - var ARRAY_PROTO = ARRAY.prototype; - var TYPEOF_OBJECT = typeof Object.prototype; - var TYPEOF_STRING = typeof String.prototype; + var ARRAY_PROTO = Array.prototype; + var OBJECT_PROTO = Object.prototype; + var TOSTRING = OBJECT_PROTO.toString; + var TOSTRING_OBJECT = TOSTRING.call(OBJECT_PROTO); + var TOSTRING_ARRAY = TOSTRING.call(ARRAY_PROTO); + var TOSTRING_STRING = TOSTRING.call(String.prototype); + var TOSTRING_FUNCTION = TOSTRING.call(Function.prototype); var RE_URI = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?(?:([^?#]*)(?:\?([^#]*))?(?:#(.*))?)/; var PROTOCOL = "protocol"; @@ -46,21 +48,21 @@ define([ "compose" ], function URIModule(Compose) { var value; var re = /(?:&|^)([^&=]*)=?([^&]*)/g; - switch (typeof arg) { - case TYPEOF_OBJECT: + switch (TOSTRING.call(arg)) { + case TOSTRING_OBJECT: for (key in arg) { self[key] = arg[key]; } break; - case TYPEOF_STRING: - while (matches = re.exec(str)) { + case TOSTRING_STRING: + while (matches = re.exec(arg)) { key = matches[1]; if (key in self) { value = self[key]; - if (value instanceof ARRAY) { + if (TOSTRING.call(value) === TOSTRING_ARRAY) { value[value.length] = matches[2]; } else { @@ -84,7 +86,7 @@ define([ "compose" ], function URIModule(Compose) { var j; for (key in self) { - if (self[key] instanceof FUNCTION) { + if (TOSTRING.call(self[key]) === TOSTRING_FUNCTION) { continue; } @@ -97,7 +99,7 @@ define([ "compose" ], function URIModule(Compose) { key = query[i]; value = self[key]; - if (value instanceof ARRAY) { + if (TOSTRING.call(value) === TOSTRING_ARRAY) { value = value.slice(0); value.sort(); @@ -166,19 +168,19 @@ define([ "compose" ], function URIModule(Compose) { var key; if (!(PROTOCOL in self)) { - uri.splice(0, 3); + uri[0] = uri[1] = ""; } if (!(PATH in self)) { - uri.splice(0, 2); + uri[3] = uri[4] = ""; } - if (!(ANCHOR in self)) { - uri.splice(-2, 2); + if (!(QUERY in self)) { + uri[5] = uri[6] = ""; } - if (!(QUERY in self)) { - uri.splice(-2, 2); + if (!(ANCHOR in self)) { + uri[7] = uri[8] = ""; } i = uri.length; diff --git a/test/util/uri.js b/test/util/uri.js new file mode 100644 index 0000000..4d0c805 --- /dev/null +++ b/test/util/uri.js @@ -0,0 +1,850 @@ +buster.testCase("URI", function (run) { + require( [ "troopjs-core/util/uri" ] , function (URI) { + run({ + "http://" : function () { + var source = "http://"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol : "http" + }); + + assert.match(uri.toString(), source); + }, + + "https://" : function() { + var source = "https://"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol : "https" + }); + + assert.match(uri.toString(), source); + }, + + "http://host" : function () { + var source = "http://host"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host", + authority : "host" + }); + + assert.match(uri.toString(), source); + }, + + "http://host/" : function () { + var source = "http://host/"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host", + authority : "host", + path : [ "" ] + }); + + assert.match(uri.toString(), source); + }, + + "http://host.com" : function () { + var source = "http://host.com"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + authority : "host.com" + }); + + assert.match(uri.toString(), source); + }, + + "http://subdomain.host.com" : function () { + var source = "http://subdomain.host.com"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "subdomain.host.com", + authority : "subdomain.host.com" + }); + + assert.match(uri.toString(), source); + }, + + "http://host.com:81" : function () { + var source = "http://host.com:81"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "host.com:81" + }); + + assert.match(uri.toString(), source); + }, + + "http://user@host.com" : function () { + var source = "http://user@host.com"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + authority : "user@host.com", + user : "user" + }); + + assert.match(uri.toString(), source); + }, + + "http://user@host.com:81" : function () { + var source = "http://user@host.com:81"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user@host.com:81", + user : "user" + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com" : function () { + var source = "http://user:pass@host.com"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + authority : "user:pass@host.com", + user : "user", + password : "pass" + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81" : function () { + var source = "http://user:pass@host.com:81"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass" + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81?query" : function () { + var source = "http://user:pass@host.com:81?query"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + query : { + query : "" + } + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81#anchor" : function () { + var source = "http://user:pass@host.com:81#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/" : function () { + var source = "http://user:pass@host.com:81/"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "" ] + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/?query" : function () { + var source = "http://user:pass@host.com:81/?query"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "" ], + query : { + query : "" + } + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/#anchor" : function () { + var source = "http://user:pass@host.com:81/#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "" ], + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/file.ext" : function () { + var source = "http://user:pass@host.com:81/file.ext"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "file.ext" ] + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory" : function () { + var source = "http://user:pass@host.com:81/directory"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory" ] + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory?query" : function () { + var source = "http://user:pass@host.com:81/directory?query"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory" ], + query : { + query : "" + } + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory#anchor" : function () { + var source = "http://user:pass@host.com:81/directory#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory" ], + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory/#anchor" : function () { + var source = "http://user:pass@host.com:81/directory/#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory", "" ], + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory/sub.directory/" : function () { + var source = "http://user:pass@host.com:81/directory/sub.directory/"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory", "sub.directory", "" ] + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory/sub.directory/file.ext" : function () { + var source = "http://user:pass@host.com:81/directory/sub.directory/file.ext"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory", "sub.directory", "file.ext" ] + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory/file.ext?query" : function () { + var source = "http://user:pass@host.com:81/directory/file.ext?query"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory", "file.ext" ], + query : { + query : "" + } + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory/file.ext?query=1&test=2" : function () { + var source = "http://user:pass@host.com:81/directory/file.ext?query=1&test=2"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory", "file.ext" ], + query : { + query : "1", + test : "2" + } + }); + + assert.match(uri.toString(), source); + }, + + "http://user:pass@host.com:81/directory/file.ext?query=1#anchor" : function () { + var source = "http://user:pass@host.com:81/directory/file.ext?query=1#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol: "http", + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "pass", + path : [ "directory", "file.ext" ], + query : { + query : "1" + }, + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "////host.com" : function () { + var source = "//host.com"; + var uri = URI(source); + + assert.match(uri, { + source : source, + host : "host.com", + authority : "host.com" + }); + + assert.match(uri.toString(), source); + }, + + "////user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { + var source = "//user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + host : "host.com", + port : 81, + authority : "user:pass@host.com:81", + user : "user", + password : "password", + path : [ "direc.tory", "file.ext" ], + query : { + query : "1", + test : "2" + }, + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "/directory/sub.directory/file.ext?query=1&test=2#anchor" : function () { + var source = "/directory/sub.directory/file.ext?query=1&test=2#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "directory", "sub.directory", "file.ext" ], + query : { + query : "1", + test : "2" + }, + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "/directory/" : function () { + var source = "/directory/"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "directory", "" ] + }); + + assert.match(uri.toString(), source); + }, + + "/file.ext" : function () { + var source = "/file.ext"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "file.ext" ] + }); + + assert.match(uri.toString(), source); + }, + + "/?query" : function () { + var source = "/?query"; + var uri = URI(source); + + assert.match(uri, { + source : source, + query : { + query : "" + } + }); + + assert.match(uri.toString(), source); + }, + + "/?query=1&test=2#anchor" : function () { + var source = "/?query=1&test=2#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + query : { + query : "1", + test : "2" + }, + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "#anchor" : function () { + var source = "#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "path/to/file" : function () { + var source = "path/to/file"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "path", "to", "file" ] + }); + + assert.match(uri.toString(), source); + }, + + "localhost" : function () { + var source = "localhost"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "localhost" ] + }); + + assert.match(uri.toString(), source); + }, + + "192.168.1.1" : function () { + var source = "192.168.1.1"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "192.168.1.1" ] + }); + + assert.match(uri.toString(), source); + }, + + "host.com" : function () { + var source = "host.com"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "host.com" ] + }); + + assert.match(uri.toString(), source); + }, + + "//host.com:81" : function () { + var source = "host.com:81"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol : "host.com", + path : [ "81" ] + }); + + assert.match(uri.toString(), source); + }, + + "//host.com:81/" : function () { + var source = "host.com:81/"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol : "host.com", + path : [ "81", "" ] + }); + + assert.match(uri.toString(), source); + }, + + "host.com?query" : function () { + var source = "host.com?query"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "host.com" ], + query : { + query : "" + } + }); + + assert.match(uri.toString(), source); + }, + + "host.com#anchor" : function () { + var source = "host.com#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "host.com" ], + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "host.com/" : function () { + var source = "host.com/"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "host.com", "" ] + }); + + assert.match(uri.toString(), source); + }, + + "host.com/file.ext" : function () { + var source = "host.com/file.ext"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "host.com", "file.ext" ] + }); + + assert.match(uri.toString(), source); + }, + + "host.com/directory/?query" : function () { + var source = "host.com/directory/?query"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "host.com", "directory", "" ], + query : { + query : "" + } + }); + + assert.match(uri.toString(), source); + }, + + "host.com/directory/#anchor" : function () { + var source = "host.com/directory/#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "host.com", "directory", "" ], + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "host.com/directory/file.ext" : function () { + var source = "host.com/directory/file.ext"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "host.com", "directory", "file.ext" ] + }); + + assert.match(uri.toString(), source); + }, + + "//host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { + var source = "host.com:81/direc.tory/file.ext?query=1&test=2#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol : "host.com", + path : [ "81", "direc.tory", "file.ext" ], + query : { + query : "1", + test : "2" + }, + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "user@host.com" : function () { + var source = "user@host.com"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "user@host.com" ] + }); + + assert.match(uri.toString(), source); + }, + + "//user@host.com:81" : function () { + var source = "user@host.com:81"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol : "user@host.com", + path : [ "81" ] + }); + + assert.match(uri.toString(), source); + }, + + "user@host.com/" : function () { + var source = "user@host.com/"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "user@host.com", "" ] + }); + + assert.match(uri.toString(), source); + }, + + "user@host.com/file.ext" : function () { + var source = "user@host.com/file.ext"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "user@host.com", "file.ext" ] + }); + + assert.match(uri.toString(), source); + }, + + "user@host.com?query" : function () { + var source = "user@host.com?query"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "user@host.com" ], + query : { + query : "" + } + }); + + assert.match(uri.toString(), source); + }, + + "user@host.com#anchor" : function () { + var source = "user@host.com#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + path : [ "user@host.com" ], + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + }, + + "//user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { + var source = "user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor"; + var uri = URI(source); + + assert.match(uri, { + source : source, + protocol : "user:", + path : [ "pass@host.com:81", "direc.tory", "file.ext" ], + anchor : "anchor" + }); + + assert.match(uri.toString(), source); + } + }); + }); +}); \ No newline at end of file From e500b2d88654104bb181b9bd17068fe605f7d5c1 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 24 Jul 2012 11:57:37 +0800 Subject: [PATCH 31/43] remove authority if there is none --- src/util/uri.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/util/uri.js b/src/util/uri.js index da3cc4b..48b78ed 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -81,6 +81,7 @@ define([ "compose" ], function URIModule(Compose) { var self = this; var key = NULL; var value = NULL; + var values; var query = []; var i = 0; var j; @@ -171,6 +172,10 @@ define([ "compose" ], function URIModule(Compose) { uri[0] = uri[1] = ""; } + if (!(AUTHORITY in self)) { + uri[2] = uri[3] = ""; + } + if (!(PATH in self)) { uri[3] = uri[4] = ""; } From 77a217496a77ed91267393bb87cdfcc601c491fc Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 24 Jul 2012 11:58:01 +0800 Subject: [PATCH 32/43] don't add '=' if there is no value --- src/util/uri.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/util/uri.js b/src/util/uri.js index 48b78ed..77d0b92 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -101,20 +101,26 @@ define([ "compose" ], function URIModule(Compose) { value = self[key]; if (TOSTRING.call(value) === TOSTRING_ARRAY) { - value = value.slice(0); + values = value.slice(0); - value.sort(); + values.sort(); - j = value.length; + j = values.length; while (j--) { - value[j] = key + "=" + value[j]; + value = values[j]; + + values[j] = value === "" + ? key + : key + "=" + value; } - query[i] = value.join("&"); + query[i] = values.join("&"); } else { - query[i] = key + "=" + value; + query[i] = value === "" + ? key + : key + "=" + value; } } From bd84009fae2f126c84dc18c1eb80384b93e76dc4 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 24 Jul 2012 11:58:23 +0800 Subject: [PATCH 33/43] add test case for empty uri --- test/util/uri.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/util/uri.js b/test/util/uri.js index 4d0c805..f3ee2e0 100644 --- a/test/util/uri.js +++ b/test/util/uri.js @@ -1,6 +1,13 @@ buster.testCase("URI", function (run) { require( [ "troopjs-core/util/uri" ] , function (URI) { run({ + "(empty)" : function () { + var source = ""; + var uri = URI(source); + + assert.match(uri.toString(), source); + }, + "http://" : function () { var source = "http://"; var uri = URI(source); From d995eacbdf71057a90828d86b72baafc0fd0e8e3 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 24 Jul 2012 11:59:16 +0800 Subject: [PATCH 34/43] use commit.same vs. commit.match on toString --- test/util/uri.js | 118 +++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/test/util/uri.js b/test/util/uri.js index f3ee2e0..c202869 100644 --- a/test/util/uri.js +++ b/test/util/uri.js @@ -17,7 +17,7 @@ buster.testCase("URI", function (run) { protocol : "http" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "https://" : function() { @@ -29,7 +29,7 @@ buster.testCase("URI", function (run) { protocol : "https" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://host" : function () { @@ -43,7 +43,7 @@ buster.testCase("URI", function (run) { authority : "host" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://host/" : function () { @@ -58,7 +58,7 @@ buster.testCase("URI", function (run) { path : [ "" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://host.com" : function () { @@ -72,7 +72,7 @@ buster.testCase("URI", function (run) { authority : "host.com" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://subdomain.host.com" : function () { @@ -86,7 +86,7 @@ buster.testCase("URI", function (run) { authority : "subdomain.host.com" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://host.com:81" : function () { @@ -101,7 +101,7 @@ buster.testCase("URI", function (run) { authority : "host.com:81" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user@host.com" : function () { @@ -116,7 +116,7 @@ buster.testCase("URI", function (run) { user : "user" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user@host.com:81" : function () { @@ -132,7 +132,7 @@ buster.testCase("URI", function (run) { user : "user" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com" : function () { @@ -148,7 +148,7 @@ buster.testCase("URI", function (run) { password : "pass" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81" : function () { @@ -165,7 +165,7 @@ buster.testCase("URI", function (run) { password : "pass" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81?query" : function () { @@ -185,7 +185,7 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81#anchor" : function () { @@ -203,7 +203,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/" : function () { @@ -221,7 +221,7 @@ buster.testCase("URI", function (run) { path : [ "" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/?query" : function () { @@ -242,7 +242,7 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/#anchor" : function () { @@ -261,7 +261,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/file.ext" : function () { @@ -279,7 +279,7 @@ buster.testCase("URI", function (run) { path : [ "file.ext" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/directory" : function () { @@ -297,7 +297,7 @@ buster.testCase("URI", function (run) { path : [ "directory" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/directory?query" : function () { @@ -318,7 +318,7 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/directory#anchor" : function () { @@ -337,7 +337,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/directory/#anchor" : function () { @@ -356,7 +356,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/directory/sub.directory/" : function () { @@ -374,7 +374,7 @@ buster.testCase("URI", function (run) { path : [ "directory", "sub.directory", "" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/directory/sub.directory/file.ext" : function () { @@ -413,7 +413,7 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/directory/file.ext?query=1&test=2" : function () { @@ -435,7 +435,7 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "http://user:pass@host.com:81/directory/file.ext?query=1#anchor" : function () { @@ -457,7 +457,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "////host.com" : function () { @@ -470,7 +470,7 @@ buster.testCase("URI", function (run) { authority : "host.com" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "////user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { @@ -492,10 +492,10 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, - "/directory/sub.directory/file.ext?query=1&test=2#anchor" : function () { + "///directory/sub.directory/file.ext?query=1&test=2#anchor" : function () { var source = "/directory/sub.directory/file.ext?query=1&test=2#anchor"; var uri = URI(source); @@ -509,10 +509,10 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, - "/directory/" : function () { + "///directory/" : function () { var source = "/directory/"; var uri = URI(source); @@ -521,10 +521,10 @@ buster.testCase("URI", function (run) { path : [ "directory", "" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, - "/file.ext" : function () { + "///file.ext" : function () { var source = "/file.ext"; var uri = URI(source); @@ -533,10 +533,10 @@ buster.testCase("URI", function (run) { path : [ "file.ext" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, - "/?query" : function () { + "///?query" : function () { var source = "/?query"; var uri = URI(source); @@ -547,10 +547,10 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, - "/?query=1&test=2#anchor" : function () { + "///?query=1&test=2#anchor" : function () { var source = "/?query=1&test=2#anchor"; var uri = URI(source); @@ -563,7 +563,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "#anchor" : function () { @@ -575,7 +575,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "path/to/file" : function () { @@ -587,7 +587,7 @@ buster.testCase("URI", function (run) { path : [ "path", "to", "file" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "localhost" : function () { @@ -599,7 +599,7 @@ buster.testCase("URI", function (run) { path : [ "localhost" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "192.168.1.1" : function () { @@ -611,7 +611,7 @@ buster.testCase("URI", function (run) { path : [ "192.168.1.1" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "host.com" : function () { @@ -623,7 +623,7 @@ buster.testCase("URI", function (run) { path : [ "host.com" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "//host.com:81" : function () { @@ -636,7 +636,7 @@ buster.testCase("URI", function (run) { path : [ "81" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "//host.com:81/" : function () { @@ -649,7 +649,7 @@ buster.testCase("URI", function (run) { path : [ "81", "" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "host.com?query" : function () { @@ -664,7 +664,7 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "host.com#anchor" : function () { @@ -677,7 +677,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "host.com/" : function () { @@ -689,7 +689,7 @@ buster.testCase("URI", function (run) { path : [ "host.com", "" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "host.com/file.ext" : function () { @@ -701,7 +701,7 @@ buster.testCase("URI", function (run) { path : [ "host.com", "file.ext" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "host.com/directory/?query" : function () { @@ -716,7 +716,7 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "host.com/directory/#anchor" : function () { @@ -729,7 +729,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "host.com/directory/file.ext" : function () { @@ -741,7 +741,7 @@ buster.testCase("URI", function (run) { path : [ "host.com", "directory", "file.ext" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "//host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { @@ -759,7 +759,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "user@host.com" : function () { @@ -771,7 +771,7 @@ buster.testCase("URI", function (run) { path : [ "user@host.com" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "//user@host.com:81" : function () { @@ -784,7 +784,7 @@ buster.testCase("URI", function (run) { path : [ "81" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "user@host.com/" : function () { @@ -796,7 +796,7 @@ buster.testCase("URI", function (run) { path : [ "user@host.com", "" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "user@host.com/file.ext" : function () { @@ -808,7 +808,7 @@ buster.testCase("URI", function (run) { path : [ "user@host.com", "file.ext" ] }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "user@host.com?query" : function () { @@ -823,7 +823,7 @@ buster.testCase("URI", function (run) { } }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "user@host.com#anchor" : function () { @@ -836,7 +836,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); }, "//user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { @@ -850,7 +850,7 @@ buster.testCase("URI", function (run) { anchor : "anchor" }); - assert.match(uri.toString(), source); + assert.same(uri.toString(), source); } }); }); From cbc2c14b2ec94a8afa9dd9ef865d626866012de0 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Tue, 24 Jul 2012 20:36:53 +0800 Subject: [PATCH 35/43] allow URI.Path to be initialized from array fix bug with TOSTRING_STRING --- src/util/uri.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/util/uri.js b/src/util/uri.js index 77d0b92..18af122 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -10,6 +10,7 @@ define([ "compose" ], function URIModule(Compose) { var NULL = null; var ARRAY_PROTO = Array.prototype; var OBJECT_PROTO = Object.prototype; + var PUSH = ARRAY_PROTO.push; var TOSTRING = OBJECT_PROTO.toString; var TOSTRING_OBJECT = TOSTRING.call(OBJECT_PROTO); var TOSTRING_ARRAY = TOSTRING.call(ARRAY_PROTO); @@ -55,7 +56,7 @@ define([ "compose" ], function URIModule(Compose) { } break; - case TOSTRING_STRING: + default: while (matches = re.exec(arg)) { key = matches[1]; @@ -128,8 +129,8 @@ define([ "compose" ], function URIModule(Compose) { } }); - var Path = Compose(ARRAY_PROTO, function Path(str) { - if (!str || str.length === 0) { + var Path = Compose(ARRAY_PROTO, function Path(arg) { + if (!arg || arg.length === 0) { return; } @@ -137,8 +138,16 @@ define([ "compose" ], function URIModule(Compose) { var matches; var re = /(?:\/|^)([^\/]*)/g; - while (matches = re.exec(str)) { - self.push(matches[1]); + switch (TOSTRING.call(arg)) { + case TOSTRING_ARRAY: + PUSH.apply(self, arg); + break; + + default: + while (matches = re.exec(arg)) { + PUSH.call(self, matches[1]); + } + break; } }, { toString : function toString() { From d749847194f90f47b0dee1c08c4aff84e42e0411 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Wed, 25 Jul 2012 12:31:25 +0800 Subject: [PATCH 36/43] update URI.Path to handle absolute vs. relative paths update test cases --- src/util/uri.js | 21 +++++++-------------- test/util/uri.js | 38 ++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/util/uri.js b/src/util/uri.js index 18af122..c55f15c 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -11,6 +11,7 @@ define([ "compose" ], function URIModule(Compose) { var ARRAY_PROTO = Array.prototype; var OBJECT_PROTO = Object.prototype; var PUSH = ARRAY_PROTO.push; + var SPLIT = String.prototype.split; var TOSTRING = OBJECT_PROTO.toString; var TOSTRING_OBJECT = TOSTRING.call(OBJECT_PROTO); var TOSTRING_ARRAY = TOSTRING.call(ARRAY_PROTO); @@ -130,13 +131,7 @@ define([ "compose" ], function URIModule(Compose) { }); var Path = Compose(ARRAY_PROTO, function Path(arg) { - if (!arg || arg.length === 0) { - return; - } - var self = this; - var matches; - var re = /(?:\/|^)([^\/]*)/g; switch (TOSTRING.call(arg)) { case TOSTRING_ARRAY: @@ -144,9 +139,7 @@ define([ "compose" ], function URIModule(Compose) { break; default: - while (matches = re.exec(arg)) { - PUSH.call(self, matches[1]); - } + PUSH.apply(self, SPLIT.call(arg, "/")); break; } }, { @@ -179,7 +172,7 @@ define([ "compose" ], function URIModule(Compose) { }, { toString : function toString() { var self = this; - var uri = [ PROTOCOL , "://", AUTHORITY, "/", PATH, "?", QUERY, "#", ANCHOR ]; + var uri = [ PROTOCOL , "://", AUTHORITY, PATH, "?", QUERY, "#", ANCHOR ]; var i; var key; @@ -188,19 +181,19 @@ define([ "compose" ], function URIModule(Compose) { } if (!(AUTHORITY in self)) { - uri[2] = uri[3] = ""; + uri[2] = ""; } if (!(PATH in self)) { - uri[3] = uri[4] = ""; + uri[3] = ""; } if (!(QUERY in self)) { - uri[5] = uri[6] = ""; + uri[4] = uri[5] = ""; } if (!(ANCHOR in self)) { - uri[7] = uri[8] = ""; + uri[6] = uri[7] = ""; } i = uri.length; diff --git a/test/util/uri.js b/test/util/uri.js index c202869..185e181 100644 --- a/test/util/uri.js +++ b/test/util/uri.js @@ -276,7 +276,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "file.ext" ] + path : [ "", "file.ext" ] }); assert.same(uri.toString(), source); @@ -294,7 +294,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory" ] + path : [ "", "directory" ] }); assert.same(uri.toString(), source); @@ -312,7 +312,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory" ], + path : [ "", "directory" ], query : { query : "" } @@ -333,7 +333,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory" ], + path : [ "", "directory" ], anchor : "anchor" }); @@ -352,7 +352,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory", "" ], + path : [ "", "directory", "" ], anchor : "anchor" }); @@ -371,7 +371,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory", "sub.directory", "" ] + path : [ "", "directory", "sub.directory", "" ] }); assert.same(uri.toString(), source); @@ -389,7 +389,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory", "sub.directory", "file.ext" ] + path : [ "", "directory", "sub.directory", "file.ext" ] }); assert.match(uri.toString(), source); @@ -407,7 +407,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory", "file.ext" ], + path : [ "", "directory", "file.ext" ], query : { query : "" } @@ -428,7 +428,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory", "file.ext" ], + path : [ "", "directory", "file.ext" ], query : { query : "1", test : "2" @@ -450,7 +450,7 @@ buster.testCase("URI", function (run) { authority : "user:pass@host.com:81", user : "user", password : "pass", - path : [ "directory", "file.ext" ], + path : [ "", "directory", "file.ext" ], query : { query : "1" }, @@ -495,13 +495,13 @@ buster.testCase("URI", function (run) { assert.same(uri.toString(), source); }, - "///directory/sub.directory/file.ext?query=1&test=2#anchor" : function () { + "/directory/sub.directory/file.ext?query=1&test=2#anchor" : function () { var source = "/directory/sub.directory/file.ext?query=1&test=2#anchor"; var uri = URI(source); assert.match(uri, { source : source, - path : [ "directory", "sub.directory", "file.ext" ], + path : [ "", "directory", "sub.directory", "file.ext" ], query : { query : "1", test : "2" @@ -512,36 +512,37 @@ buster.testCase("URI", function (run) { assert.same(uri.toString(), source); }, - "///directory/" : function () { + "/directory/" : function () { var source = "/directory/"; var uri = URI(source); assert.match(uri, { source : source, - path : [ "directory", "" ] + path : [ "", "directory", "" ] }); assert.same(uri.toString(), source); }, - "///file.ext" : function () { + "/file.ext" : function () { var source = "/file.ext"; var uri = URI(source); assert.match(uri, { source : source, - path : [ "file.ext" ] + path : [ "", "file.ext" ] }); assert.same(uri.toString(), source); }, - "///?query" : function () { + "/?query" : function () { var source = "/?query"; var uri = URI(source); assert.match(uri, { source : source, + path : [ "" ], query : { query : "" } @@ -550,12 +551,13 @@ buster.testCase("URI", function (run) { assert.same(uri.toString(), source); }, - "///?query=1&test=2#anchor" : function () { + "/?query=1&test=2#anchor" : function () { var source = "/?query=1&test=2#anchor"; var uri = URI(source); assert.match(uri, { source : source, + path : [ "" ], query : { query : "1", test : "2" From e18e28d69d476ef8111ecc9836ba4a6afe6aee5e Mon Sep 17 00:00:00 2001 From: chinason Date: Wed, 1 Aug 2012 09:58:13 +0800 Subject: [PATCH 37/43] Update src/component/gadget.js for (i = bases.length; i >= 0; i--) { should be for (i = bases.length - 1; i >= 0; i--) { --- src/component/gadget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/gadget.js b/src/component/gadget.js index ba621b0..c22ce92 100644 --- a/src/component/gadget.js +++ b/src/component/gadget.js @@ -33,7 +33,7 @@ define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function Ga var key = null; // Iterate base chain (while there's a prototype) - for (i = bases.length; i >= 0; i--) { + for (i = bases.length - 1; i >= 0; i--) { base = bases[i]; add: for (key in base) { From b4da7b27abd4112b4e66206d66d9effa3b328a76 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 2 Aug 2012 16:02:42 +0800 Subject: [PATCH 38/43] lint friendly --- src/component/base.js | 6 +- src/component/gadget.js | 12 +- src/component/widget.js | 11 +- src/pubsub/hub.js | 235 ++++++++++++++++++++------------------ src/pubsub/topic.js | 2 + src/util/uri.js | 27 ++--- src/widget/placeholder.js | 2 + 7 files changed, 152 insertions(+), 143 deletions(-) diff --git a/src/component/base.js b/src/component/base.js index c432e1b..c1c7028 100644 --- a/src/component/base.js +++ b/src/component/base.js @@ -3,10 +3,8 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ -/** - * The base trait provides functionality for instance counting, - * configuration and a default 'toString' method. - */ +/*jshint strict:false, smarttabs:true */ +/*global define:true */ define([ "compose", "config" ], function ComponentModule(Compose, config) { var COUNT = 0; diff --git a/src/component/gadget.js b/src/component/gadget.js index c22ce92..9ec695c 100644 --- a/src/component/gadget.js +++ b/src/component/gadget.js @@ -3,10 +3,10 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ -/** - * The gadget trait provides life cycle management - */ +/*jshint strict:false, smarttabs:true, newcap:false, forin:false, loopfunc:true */ +/*global define:true */ define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function GadgetModule(Compose, Component, Deferred, hub) { + var UNDEFINED; var NULL = null; var FUNCTION = Function; var RE_HUB = /^hub(?::(\w+))?\/(.+)/; @@ -80,7 +80,7 @@ define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function Ga // Extend self Compose.call(self, { - signal : function signal(signal, deferred) { + signal : function onSignal(signal, deferred) { var _self = this; var _callbacks; var _j; @@ -172,7 +172,7 @@ define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function Ga var subscription; // Loop over subscriptions - while (subscription = subscriptions.shift()) { + while ((subscription = subscriptions.shift()) !== UNDEFINED) { hub.unsubscribe(subscription[0], subscription[1], subscription[2]); } @@ -184,7 +184,7 @@ define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function Ga }, /** - * Calls hub.publish in self context + * Calls hub.publish in self context * @returns self */ publish : function publish() { diff --git a/src/component/widget.js b/src/component/widget.js index 2fd19ab..e7d5f34 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -3,13 +3,12 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ -/** - * The widget trait provides common UI related logic - */ +/*jshint strict:false, smarttabs:true, newcap:false */ +/*global define:true */ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadget, $, Deferred) { + var UNDEFINED; var NULL = null; var FUNCTION = Function; - var UNDEFINED = undefined; var ARRAY_PROTO = Array.prototype; var SHIFT = ARRAY_PROTO.shift; var UNSHIFT = ARRAY_PROTO.unshift; @@ -121,7 +120,7 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge "sig/initialize" : function initialize(signal, deferred) { var self = this; var $element = self[$ELEMENT]; - var $proxies = self[$PROXIES] = [];; + var $proxies = self[$PROXIES] = []; var key = NULL; var value; var matches; @@ -172,7 +171,7 @@ define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadge var $proxy; // Loop over subscriptions - while ($proxy = $proxies.shift()) { + while (($proxy = $proxies.shift()) !== UNDEFINED) { $element.unbind($proxy[0], $proxy[1]); } diff --git a/src/pubsub/hub.js b/src/pubsub/hub.js index 9220e04..d2cf279 100644 --- a/src/pubsub/hub.js +++ b/src/pubsub/hub.js @@ -3,7 +3,10 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ +/*jshint strict:false, smarttabs:true, laxbreak:true */ +/*global define:true */ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose, Component, Topic) { + var UNDEFINED; var FUNCTION = Function; var MEMORY = "memory"; var CONTEXT = "context"; @@ -31,10 +34,11 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose */ subscribe : function subscribe(topic /*, context, memory, callback, callback, ..*/) { var self = this; - var length = arguments[LENGTH]; - var context = arguments[1]; - var memory = arguments[2]; - var callback = arguments[3]; + var arg = arguments; + var length = arg[LENGTH]; + var context = arg[1]; + var memory = arg[2]; + var callback = arg[3]; var offset; var handlers; var handler; @@ -79,7 +83,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Create new handler handler = { - "callback" : arguments[offset++], + "callback" : arg[offset++], "context" : context }; @@ -94,7 +98,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose while (offset < length) { // Set tail -> tail.next -> handler tail = tail[NEXT] = { - "callback" : arguments[offset++], + "callback" : arg[offset++], "context" : context }; } @@ -110,39 +114,45 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose // Get handled handled = memory[HANDLED]; - // Loop through handlers, optimize for arguments - if (memory[LENGTH] > 0 ) while(handler) { - // Skip to next handler if this handler has already been handled - if (handler[HANDLED] === handled) { - handler = handler[NEXT]; - continue; - } + // Optimize for arguments + if (memory[LENGTH] > 0 ) { + // Loop through handlers + while(handler) { + // Skip to next handler if this handler has already been handled + if (handler[HANDLED] === handled) { + handler = handler[NEXT]; + continue; + } - // Store handled - handler[HANDLED] = handled; + // Store handled + handler[HANDLED] = handled; - // Apply handler callback - handler[CALLBACK].apply(handler[CONTEXT], memory); + // Apply handler callback + handler[CALLBACK].apply(handler[CONTEXT], memory); - // Update handler - handler = handler[NEXT]; - } - // Loop through handlers, optimize for no arguments - else while(handler) { - // Skip to next handler if this handler has already been handled - if (handler[HANDLED] === handled) { + // Update handler handler = handler[NEXT]; - continue; } + } + // Optimize for no arguments + else { + // Loop through handlers + while(handler) { + // Skip to next handler if this handler has already been handled + if (handler[HANDLED] === handled) { + handler = handler[NEXT]; + continue; + } - // Store handled - handler[HANDLED] = handled; + // Store handled + handler[HANDLED] = handled; - // Call handler callback - handler[CALLBACK].call(handler[CONTEXT]); + // Call handler callback + handler[CALLBACK].call(handler[CONTEXT]); - // Update handler - handler = handler[NEXT]; + // Update handler + handler = handler[NEXT]; + } } } } @@ -150,7 +160,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose else { // Create head and tail head = tail = { - "callback" : arguments[offset++], + "callback" : arg[offset++], "context" : context }; @@ -158,7 +168,7 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose while (offset < length) { // Set tail -> tail.next -> handler tail = tail[NEXT] = { - "callback" : arguments[offset++], + "callback" : arg[offset++], "context" : context }; } @@ -183,9 +193,11 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose * @returns self */ unsubscribe : function unsubscribe(topic /*, context, callback, callback, ..*/) { - var length = arguments[LENGTH]; - var context = arguments[1]; - var callback = arguments[2]; + var self = this; + var arg = arguments; + var length = arg[LENGTH]; + var context = arg[1]; + var callback = arg[2]; var offset; var handlers; var handler; @@ -207,60 +219,58 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose return self; } - unsubscribe: { - // Fast fail if we don't have subscribers - if (!(topic in HANDLERS)) { - break unsubscribe; - } - - // Get handlers - handlers = HANDLERS[topic]; + // Fast fail if we don't have subscribers + if (!(topic in HANDLERS)) { + return self; + } - // Get head - head = handlers[HEAD]; + // Get handlers + handlers = HANDLERS[topic]; - // Loop over remaining arguments - while (offset < length) { - // Store callback - callback = arguments[offset++]; + // Get head + head = handlers[HEAD]; - // Get first handler - handler = previous = head; + // Loop over remaining arguments + while (offset < length) { + // Store callback + callback = arg[offset++]; - // Loop through handlers - do { - // Check if this handler should be unlinked - if (handler[CALLBACK] === callback && handler[CONTEXT] === context) { - // Is this the first handler - if (handler === head) { - // Re-link head and previous, then - // continue - head = previous = handler[NEXT]; - continue; - } - - // Unlink current handler, then continue - previous[NEXT] = handler[NEXT]; + // Get first handler + handler = previous = head; + + // Loop through handlers + do { + // Check if this handler should be unlinked + if (handler[CALLBACK] === callback && handler[CONTEXT] === context) { + // Is this the first handler + if (handler === head) { + // Re-link head and previous, then + // continue + head = previous = handler[NEXT]; continue; } - // Update previous pointer - previous = handler; - } while (handler = handler[NEXT]); - } + // Unlink current handler, then continue + previous[NEXT] = handler[NEXT]; + continue; + } - // Update head and tail - if (head && previous) { - handlers[HEAD] = head; - handlers[TAIL] = previous; - } - else { - delete handlers[HEAD]; - delete handlers[TAIL]; - } + // Update previous pointer + previous = handler; + } while ((handler = handler[NEXT]) !== UNDEFINED); } - return this; + // Update head and tail + if (head && previous) { + handlers[HEAD] = head; + handlers[TAIL] = previous; + } + else { + delete handlers[HEAD]; + delete handlers[TAIL]; + } + + return self; }, /** @@ -271,11 +281,12 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose * @returns self */ publish : function publish(topic /*, arg, arg, ..*/) { + var arg = arguments; var handlers; var handler; // Store handled - var handled = arguments[HANDLED] = COUNT++; + var handled = arg[HANDLED] = COUNT++; // Have handlers if (topic in HANDLERS) { @@ -283,53 +294,59 @@ define([ "compose", "../component/base", "./topic" ], function HubModule(Compose handlers = HANDLERS[topic]; // Remember arguments - handlers[MEMORY] = arguments; + handlers[MEMORY] = arg; // Get first handler handler = handlers[HEAD]; - // Loop through handlers, optimize for arguments - if (arguments[LENGTH] > 0) while(handler) { - // Skip to next handler if this handler has already been handled - if (handler[HANDLED] === handled) { - handler = handler[NEXT]; - continue; - } + // Optimize for arguments + if (arg[LENGTH] > 0) { + // Loop through handlers + while(handler) { + // Skip to next handler if this handler has already been handled + if (handler[HANDLED] === handled) { + handler = handler[NEXT]; + continue; + } - // Update handled - handler[HANDLED] = handled; + // Update handled + handler[HANDLED] = handled; - // Apply handler callback - handler[CALLBACK].apply(handler[CONTEXT], arguments); + // Apply handler callback + handler[CALLBACK].apply(handler[CONTEXT], arg); - // Update handler - handler = handler[NEXT]; - } - // Loop through handlers, optimize for no arguments - else while(handler) { - // Skip to next handler if this handler has already been handled - if (handler[HANDLED] === handled) { + // Update handler handler = handler[NEXT]; - continue; } + } + // Optimize for no arguments + else { + // Loop through handlers + while(handler) { + // Skip to next handler if this handler has already been handled + if (handler[HANDLED] === handled) { + handler = handler[NEXT]; + continue; + } - // Update handled - handler[HANDLED] = handled; + // Update handled + handler[HANDLED] = handled; - // Call handler callback - handler[CALLBACK].call(handler[CONTEXT]); + // Call handler callback + handler[CALLBACK].call(handler[CONTEXT]); - // Update handler - handler = handler[NEXT]; + // Update handler + handler = handler[NEXT]; + } } } // No handlers - else if (arguments[LENGTH] > 0){ + else if (arg[LENGTH] > 0){ // Create handlers and store with topic HANDLERS[topic] = handlers = {}; // Remember arguments - handlers[MEMORY] = arguments; + handlers[MEMORY] = arg; } return this; diff --git a/src/pubsub/topic.js b/src/pubsub/topic.js index 1612b94..e208ffd 100644 --- a/src/pubsub/topic.js +++ b/src/pubsub/topic.js @@ -3,6 +3,8 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ +/*jshint strict:false, smarttabs:true, laxbreak:true */ +/*global define:true */ define([ "../component/base", "../util/unique" ], function TopicModule(Component, unique) { var TOSTRING = Object.prototype.toString; var TOSTRING_ARRAY = TOSTRING.call(Array.prototype); diff --git a/src/util/uri.js b/src/util/uri.js index c55f15c..9270b83 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -6,7 +6,10 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ +/*jshint strict:false, smarttabs:true, laxbreak:true, newcap:false, forin:false, loopfunc:true */ +/*global define:true */ define([ "compose" ], function URIModule(Compose) { + var UNDEFINED; var NULL = null; var ARRAY_PROTO = Array.prototype; var OBJECT_PROTO = Object.prototype; @@ -50,15 +53,12 @@ define([ "compose" ], function URIModule(Compose) { var value; var re = /(?:&|^)([^&=]*)=?([^&]*)/g; - switch (TOSTRING.call(arg)) { - case TOSTRING_OBJECT: + if (TOSTRING.call(arg) === TOSTRING_OBJECT) { for (key in arg) { self[key] = arg[key]; } - break; - - default: - while (matches = re.exec(arg)) { + } else { + while ((matches = re.exec(arg)) !== UNDEFINED) { key = matches[1]; if (key in self) { @@ -75,7 +75,6 @@ define([ "compose" ], function URIModule(Compose) { self[key] = matches[2]; } } - break; } }, { @@ -131,17 +130,9 @@ define([ "compose" ], function URIModule(Compose) { }); var Path = Compose(ARRAY_PROTO, function Path(arg) { - var self = this; - - switch (TOSTRING.call(arg)) { - case TOSTRING_ARRAY: - PUSH.apply(self, arg); - break; - - default: - PUSH.apply(self, SPLIT.call(arg, "/")); - break; - } + PUSH.apply(this, TOSTRING.call(arg) === TOSTRING_ARRAY + ? arg + : SPLIT.call(arg, "/")); }, { toString : function toString() { return this.join("/"); diff --git a/src/widget/placeholder.js b/src/widget/placeholder.js index 4839613..28d8634 100644 --- a/src/widget/placeholder.js +++ b/src/widget/placeholder.js @@ -3,6 +3,8 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ +/*jshint strict:false, smarttabs:true, laxbreak:true */ +/*global define:true */ define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholderModule(Widget, Deferred) { var FUNCTION = Function; var POP = Array.prototype.pop; From 39557486e8a895aa65d8037f4ba7ff14a699d783 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 2 Aug 2012 16:03:28 +0800 Subject: [PATCH 39/43] updated VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ae877a8..21e8796 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2+ +1.0.3 From 37b78c8f393ff7cb594e2f9be404b0c5930173eb Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 2 Aug 2012 16:04:36 +0800 Subject: [PATCH 40/43] updated VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 21e8796..238cb5c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.3 +1.0.3+ From 1c73d2d43e22b55054355b511a542b24cf08eea6 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Thu, 2 Aug 2012 16:42:25 +0800 Subject: [PATCH 41/43] better support for matches and null --- src/util/uri.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/util/uri.js b/src/util/uri.js index 9270b83..0fb1857 100644 --- a/src/util/uri.js +++ b/src/util/uri.js @@ -9,7 +9,6 @@ /*jshint strict:false, smarttabs:true, laxbreak:true, newcap:false, forin:false, loopfunc:true */ /*global define:true */ define([ "compose" ], function URIModule(Compose) { - var UNDEFINED; var NULL = null; var ARRAY_PROTO = Array.prototype; var OBJECT_PROTO = Object.prototype; @@ -58,7 +57,7 @@ define([ "compose" ], function URIModule(Compose) { self[key] = arg[key]; } } else { - while ((matches = re.exec(arg)) !== UNDEFINED) { + while ((matches = re.exec(arg)) !== NULL) { key = matches[1]; if (key in self) { @@ -141,15 +140,19 @@ define([ "compose" ], function URIModule(Compose) { var URI = Compose(function URI(str) { var self = this; - var matches = RE_URI.exec(str); - var i = matches.length; var value; + var matches; + var i; + + if ((matches = RE_URI.exec(str)) !== NULL) { + i = matches.length; - while (i--) { - value = matches[i]; + while (i--) { + value = matches[i]; - if (value) { - self[KEYS[i]] = value; + if (value) { + self[KEYS[i]] = value; + } } } From 3105743f4b47068dba36a47b4a79a001660986a4 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Fri, 3 Aug 2012 17:39:23 +0800 Subject: [PATCH 42/43] moved utils --- src/component/gadget.js | 2 +- src/component/widget.js | 2 +- src/pubsub/topic.js | 2 +- src/remote/ajax.js | 2 +- src/route/router.js | 2 +- src/util/callbacks.js | 8 - src/util/deferred.js | 8 - src/util/each.js | 8 - src/util/grep.js | 8 - src/util/merge.js | 42 -- src/util/tr.js | 30 -- src/util/unique.js | 30 -- src/util/uri.js | 214 ---------- src/util/when.js | 8 - src/widget/application.js | 2 +- src/widget/placeholder.js | 2 +- test/util/uri.js | 859 -------------------------------------- 17 files changed, 7 insertions(+), 1222 deletions(-) delete mode 100644 src/util/callbacks.js delete mode 100644 src/util/deferred.js delete mode 100644 src/util/each.js delete mode 100644 src/util/grep.js delete mode 100644 src/util/merge.js delete mode 100644 src/util/tr.js delete mode 100644 src/util/unique.js delete mode 100644 src/util/uri.js delete mode 100644 src/util/when.js delete mode 100644 test/util/uri.js diff --git a/src/component/gadget.js b/src/component/gadget.js index 9ec695c..5b84e65 100644 --- a/src/component/gadget.js +++ b/src/component/gadget.js @@ -5,7 +5,7 @@ */ /*jshint strict:false, smarttabs:true, newcap:false, forin:false, loopfunc:true */ /*global define:true */ -define([ "compose", "./base", "../util/deferred", "../pubsub/hub" ], function GadgetModule(Compose, Component, Deferred, hub) { +define([ "compose", "./base", "troopjs-utils/deferred", "../pubsub/hub" ], function GadgetModule(Compose, Component, Deferred, hub) { var UNDEFINED; var NULL = null; var FUNCTION = Function; diff --git a/src/component/widget.js b/src/component/widget.js index e7d5f34..85952c9 100644 --- a/src/component/widget.js +++ b/src/component/widget.js @@ -5,7 +5,7 @@ */ /*jshint strict:false, smarttabs:true, newcap:false */ /*global define:true */ -define([ "./gadget", "jquery", "../util/deferred" ], function WidgetModule(Gadget, $, Deferred) { +define([ "./gadget", "jquery", "troopjs-utils/deferred" ], function WidgetModule(Gadget, $, Deferred) { var UNDEFINED; var NULL = null; var FUNCTION = Function; diff --git a/src/pubsub/topic.js b/src/pubsub/topic.js index e208ffd..95fb354 100644 --- a/src/pubsub/topic.js +++ b/src/pubsub/topic.js @@ -5,7 +5,7 @@ */ /*jshint strict:false, smarttabs:true, laxbreak:true */ /*global define:true */ -define([ "../component/base", "../util/unique" ], function TopicModule(Component, unique) { +define([ "../component/base", "troopjs-utils/unique" ], function TopicModule(Component, unique) { var TOSTRING = Object.prototype.toString; var TOSTRING_ARRAY = TOSTRING.call(Array.prototype); diff --git a/src/remote/ajax.js b/src/remote/ajax.js index 16faa4e..4e2fc36 100644 --- a/src/remote/ajax.js +++ b/src/remote/ajax.js @@ -3,7 +3,7 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ -define([ "../component/service", "../pubsub/topic", "jquery", "../util/merge" ], function AjaxModule(Service, Topic, $, merge) { +define([ "../component/service", "../pubsub/topic", "jquery", "troopjs-utils/merge" ], function AjaxModule(Service, Topic, $, merge) { return Service.extend({ displayName : "core/remote/ajax", diff --git a/src/route/router.js b/src/route/router.js index 504932d..37818de 100644 --- a/src/route/router.js +++ b/src/route/router.js @@ -3,7 +3,7 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ -define([ "../component/service", "../util/uri" ], function RouterModule(Service, URI) { +define([ "../component/service", "troopjs-utils/uri" ], function RouterModule(Service, URI) { var HASHCHANGE = "hashchange"; var $ELEMENT = "$element"; var ROUTE = "route"; diff --git a/src/util/callbacks.js b/src/util/callbacks.js deleted file mode 100644 index 6eb941a..0000000 --- a/src/util/callbacks.js +++ /dev/null @@ -1,8 +0,0 @@ -/*! - * TroopJS util/callbacks component - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -define([ "jquery" ], function CallbacksModule($) { - return $.Callbacks; -}); \ No newline at end of file diff --git a/src/util/deferred.js b/src/util/deferred.js deleted file mode 100644 index 9e7ad86..0000000 --- a/src/util/deferred.js +++ /dev/null @@ -1,8 +0,0 @@ -/*! - * TroopJS util/deferred component - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -define([ "jquery" ], function DeferredModule($) { - return $.Deferred; -}); \ No newline at end of file diff --git a/src/util/each.js b/src/util/each.js deleted file mode 100644 index b275618..0000000 --- a/src/util/each.js +++ /dev/null @@ -1,8 +0,0 @@ -/*! - * TroopJS util/each component - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -define([ "jquery" ], function EachModule($) { - return $.each; -}); \ No newline at end of file diff --git a/src/util/grep.js b/src/util/grep.js deleted file mode 100644 index 771d9cf..0000000 --- a/src/util/grep.js +++ /dev/null @@ -1,8 +0,0 @@ -/*! - * TroopJS util/grep component - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -define([ "jquery" ], function GrepModule($) { - return $.grep; -}); \ No newline at end of file diff --git a/src/util/merge.js b/src/util/merge.js deleted file mode 100644 index ef0be66..0000000 --- a/src/util/merge.js +++ /dev/null @@ -1,42 +0,0 @@ -/*! - * TroopJS util/merge module - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -define(function MergeModule() { - var ARRAY = Array; - var OBJECT = Object; - - return function merge(source) { - var target = this; - var key = null; - var i; - var iMax; - var value; - var constructor; - - for (i = 0, iMax = arguments.length; i < iMax; i++) { - source = arguments[i]; - - for (key in source) { - value = source[key]; - constructor = value.constructor; - - if (!(key in target)) { - target[key] = value; - } - else if (constructor === ARRAY) { - target[key] = target[key].concat(value); - } - else if (constructor === OBJECT) { - merge.call(target[key], value); - } - else { - target[key] = value; - } - } - } - - return target; - }; -}); \ No newline at end of file diff --git a/src/util/tr.js b/src/util/tr.js deleted file mode 100644 index 67c31dc..0000000 --- a/src/util/tr.js +++ /dev/null @@ -1,30 +0,0 @@ -/*! - * TroopJS util/tr component - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -define(function TrModule() { - var TYPEOF_NUMBER = typeof Number(); - - return function tr(callback) { - var self = this; - var result = []; - var i; - var length = self.length; - var key; - - // Is this an array? Basically, is length a number, is it 0 or is it greater than 0 and that we have index 0 and index length-1 - if (typeof length === TYPEOF_NUMBER && length === 0 || length > 0 && 0 in self && length - 1 in self) { - for (i = 0; i < length; i++) { - result.push(callback.call(self, self[i], i)); - } - // Otherwise we'll iterate it as an object - } else if (self){ - for (key in self) { - result.push(callback.call(self, self[key], key)); - } - } - - return result; - }; -}); \ No newline at end of file diff --git a/src/util/unique.js b/src/util/unique.js deleted file mode 100644 index b5c1eae..0000000 --- a/src/util/unique.js +++ /dev/null @@ -1,30 +0,0 @@ -/*! - * TroopJS util/unique component - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -define(function UniqueModule() { - return function unique(callback) { - var self = this; - var length = self.length; - var result = []; - var value; - var i; - var j; - var k; - - add: for (i = j = k = 0; i < length; i++, j = 0) { - value = self[i]; - - while(j < k) { - if (callback.call(self, value, result[j++]) === true) { - continue add; - } - } - - result[k++] = value; - } - - return result; - }; -}); \ No newline at end of file diff --git a/src/util/uri.js b/src/util/uri.js deleted file mode 100644 index 0fb1857..0000000 --- a/src/util/uri.js +++ /dev/null @@ -1,214 +0,0 @@ -/*! - * TroopJS util/uri module - * - * parts of code from parseUri 1.2.2 Copyright Steven Levithan - * - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -/*jshint strict:false, smarttabs:true, laxbreak:true, newcap:false, forin:false, loopfunc:true */ -/*global define:true */ -define([ "compose" ], function URIModule(Compose) { - var NULL = null; - var ARRAY_PROTO = Array.prototype; - var OBJECT_PROTO = Object.prototype; - var PUSH = ARRAY_PROTO.push; - var SPLIT = String.prototype.split; - var TOSTRING = OBJECT_PROTO.toString; - var TOSTRING_OBJECT = TOSTRING.call(OBJECT_PROTO); - var TOSTRING_ARRAY = TOSTRING.call(ARRAY_PROTO); - var TOSTRING_STRING = TOSTRING.call(String.prototype); - var TOSTRING_FUNCTION = TOSTRING.call(Function.prototype); - var RE_URI = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?(?:([^?#]*)(?:\?([^#]*))?(?:#(.*))?)/; - - var PROTOCOL = "protocol"; - var AUTHORITY = "authority"; - var PATH = "path"; - var QUERY = "query"; - var ANCHOR = "anchor"; - - var KEYS = [ "source", - PROTOCOL, - AUTHORITY, - "userInfo", - "user", - "password", - "host", - "port", - PATH, - QUERY, - ANCHOR ]; - - // Store current Compose.secure setting - var SECURE = Compose.secure; - - // Prevent Compose from creating constructor property - Compose.secure = true; - - var Query = Compose(function Query(arg) { - var self = this; - var matches; - var key = NULL; - var value; - var re = /(?:&|^)([^&=]*)=?([^&]*)/g; - - if (TOSTRING.call(arg) === TOSTRING_OBJECT) { - for (key in arg) { - self[key] = arg[key]; - } - } else { - while ((matches = re.exec(arg)) !== NULL) { - key = matches[1]; - - if (key in self) { - value = self[key]; - - if (TOSTRING.call(value) === TOSTRING_ARRAY) { - value[value.length] = matches[2]; - } - else { - self[key] = [ value, matches[2] ]; - } - } - else { - self[key] = matches[2]; - } - } - } - - }, { - toString : function toString() { - var self = this; - var key = NULL; - var value = NULL; - var values; - var query = []; - var i = 0; - var j; - - for (key in self) { - if (TOSTRING.call(self[key]) === TOSTRING_FUNCTION) { - continue; - } - - query[i++] = key; - } - - query.sort(); - - while (i--) { - key = query[i]; - value = self[key]; - - if (TOSTRING.call(value) === TOSTRING_ARRAY) { - values = value.slice(0); - - values.sort(); - - j = values.length; - - while (j--) { - value = values[j]; - - values[j] = value === "" - ? key - : key + "=" + value; - } - - query[i] = values.join("&"); - } - else { - query[i] = value === "" - ? key - : key + "=" + value; - } - } - - return query.join("&"); - } - }); - - var Path = Compose(ARRAY_PROTO, function Path(arg) { - PUSH.apply(this, TOSTRING.call(arg) === TOSTRING_ARRAY - ? arg - : SPLIT.call(arg, "/")); - }, { - toString : function toString() { - return this.join("/"); - } - }); - - var URI = Compose(function URI(str) { - var self = this; - var value; - var matches; - var i; - - if ((matches = RE_URI.exec(str)) !== NULL) { - i = matches.length; - - while (i--) { - value = matches[i]; - - if (value) { - self[KEYS[i]] = value; - } - } - } - - if (QUERY in self) { - self[QUERY] = Query(self[QUERY]); - } - - if (PATH in self) { - self[PATH] = Path(self[PATH]); - } - }, { - toString : function toString() { - var self = this; - var uri = [ PROTOCOL , "://", AUTHORITY, PATH, "?", QUERY, "#", ANCHOR ]; - var i; - var key; - - if (!(PROTOCOL in self)) { - uri[0] = uri[1] = ""; - } - - if (!(AUTHORITY in self)) { - uri[2] = ""; - } - - if (!(PATH in self)) { - uri[3] = ""; - } - - if (!(QUERY in self)) { - uri[4] = uri[5] = ""; - } - - if (!(ANCHOR in self)) { - uri[6] = uri[7] = ""; - } - - i = uri.length; - - while (i--) { - key = uri[i]; - - if (key in self) { - uri[i] = self[key]; - } - } - - return uri.join(""); - } - }); - - // Restore Compose.secure setting - Compose.secure = SECURE; - - URI.Path = Path; - URI.Query = Query; - - return URI; -}); \ No newline at end of file diff --git a/src/util/when.js b/src/util/when.js deleted file mode 100644 index aa148a8..0000000 --- a/src/util/when.js +++ /dev/null @@ -1,8 +0,0 @@ -/*! - * TroopJS util/when component - * @license TroopJS Copyright 2012, Mikael Karon - * Released under the MIT license. - */ -define([ "jquery" ], function WhenModule($) { - return $.when; -}); \ No newline at end of file diff --git a/src/widget/application.js b/src/widget/application.js index 12384c9..b9c1536 100644 --- a/src/widget/application.js +++ b/src/widget/application.js @@ -3,7 +3,7 @@ * @license TroopJS Copyright 2012, Mikael Karon * Released under the MIT license. */ -define([ "../component/widget", "../util/deferred" ], function ApplicationModule(Widget, Deferred) { +define([ "../component/widget", "troopjs-utils/deferred" ], function ApplicationModule(Widget, Deferred) { return Widget.extend({ displayName : "core/widget/application", diff --git a/src/widget/placeholder.js b/src/widget/placeholder.js index 28d8634..75d9f79 100644 --- a/src/widget/placeholder.js +++ b/src/widget/placeholder.js @@ -5,7 +5,7 @@ */ /*jshint strict:false, smarttabs:true, laxbreak:true */ /*global define:true */ -define([ "../component/widget", "../util/deferred" ], function WidgetPlaceholderModule(Widget, Deferred) { +define([ "../component/widget", "troopjs-utils/deferred" ], function WidgetPlaceholderModule(Widget, Deferred) { var FUNCTION = Function; var POP = Array.prototype.pop; var HOLDING = "holding"; diff --git a/test/util/uri.js b/test/util/uri.js deleted file mode 100644 index 185e181..0000000 --- a/test/util/uri.js +++ /dev/null @@ -1,859 +0,0 @@ -buster.testCase("URI", function (run) { - require( [ "troopjs-core/util/uri" ] , function (URI) { - run({ - "(empty)" : function () { - var source = ""; - var uri = URI(source); - - assert.match(uri.toString(), source); - }, - - "http://" : function () { - var source = "http://"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol : "http" - }); - - assert.same(uri.toString(), source); - }, - - "https://" : function() { - var source = "https://"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol : "https" - }); - - assert.same(uri.toString(), source); - }, - - "http://host" : function () { - var source = "http://host"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host", - authority : "host" - }); - - assert.same(uri.toString(), source); - }, - - "http://host/" : function () { - var source = "http://host/"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host", - authority : "host", - path : [ "" ] - }); - - assert.same(uri.toString(), source); - }, - - "http://host.com" : function () { - var source = "http://host.com"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - authority : "host.com" - }); - - assert.same(uri.toString(), source); - }, - - "http://subdomain.host.com" : function () { - var source = "http://subdomain.host.com"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "subdomain.host.com", - authority : "subdomain.host.com" - }); - - assert.same(uri.toString(), source); - }, - - "http://host.com:81" : function () { - var source = "http://host.com:81"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "host.com:81" - }); - - assert.same(uri.toString(), source); - }, - - "http://user@host.com" : function () { - var source = "http://user@host.com"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - authority : "user@host.com", - user : "user" - }); - - assert.same(uri.toString(), source); - }, - - "http://user@host.com:81" : function () { - var source = "http://user@host.com:81"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user@host.com:81", - user : "user" - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com" : function () { - var source = "http://user:pass@host.com"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - authority : "user:pass@host.com", - user : "user", - password : "pass" - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81" : function () { - var source = "http://user:pass@host.com:81"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass" - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81?query" : function () { - var source = "http://user:pass@host.com:81?query"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - query : { - query : "" - } - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81#anchor" : function () { - var source = "http://user:pass@host.com:81#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/" : function () { - var source = "http://user:pass@host.com:81/"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "" ] - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/?query" : function () { - var source = "http://user:pass@host.com:81/?query"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "" ], - query : { - query : "" - } - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/#anchor" : function () { - var source = "http://user:pass@host.com:81/#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "" ], - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/file.ext" : function () { - var source = "http://user:pass@host.com:81/file.ext"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "file.ext" ] - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory" : function () { - var source = "http://user:pass@host.com:81/directory"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory" ] - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory?query" : function () { - var source = "http://user:pass@host.com:81/directory?query"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory" ], - query : { - query : "" - } - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory#anchor" : function () { - var source = "http://user:pass@host.com:81/directory#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory" ], - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory/#anchor" : function () { - var source = "http://user:pass@host.com:81/directory/#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory", "" ], - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory/sub.directory/" : function () { - var source = "http://user:pass@host.com:81/directory/sub.directory/"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory", "sub.directory", "" ] - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory/sub.directory/file.ext" : function () { - var source = "http://user:pass@host.com:81/directory/sub.directory/file.ext"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory", "sub.directory", "file.ext" ] - }); - - assert.match(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory/file.ext?query" : function () { - var source = "http://user:pass@host.com:81/directory/file.ext?query"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory", "file.ext" ], - query : { - query : "" - } - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory/file.ext?query=1&test=2" : function () { - var source = "http://user:pass@host.com:81/directory/file.ext?query=1&test=2"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory", "file.ext" ], - query : { - query : "1", - test : "2" - } - }); - - assert.same(uri.toString(), source); - }, - - "http://user:pass@host.com:81/directory/file.ext?query=1#anchor" : function () { - var source = "http://user:pass@host.com:81/directory/file.ext?query=1#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol: "http", - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "pass", - path : [ "", "directory", "file.ext" ], - query : { - query : "1" - }, - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "////host.com" : function () { - var source = "//host.com"; - var uri = URI(source); - - assert.match(uri, { - source : source, - host : "host.com", - authority : "host.com" - }); - - assert.same(uri.toString(), source); - }, - - "////user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { - var source = "//user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - host : "host.com", - port : 81, - authority : "user:pass@host.com:81", - user : "user", - password : "password", - path : [ "direc.tory", "file.ext" ], - query : { - query : "1", - test : "2" - }, - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "/directory/sub.directory/file.ext?query=1&test=2#anchor" : function () { - var source = "/directory/sub.directory/file.ext?query=1&test=2#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "", "directory", "sub.directory", "file.ext" ], - query : { - query : "1", - test : "2" - }, - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "/directory/" : function () { - var source = "/directory/"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "", "directory", "" ] - }); - - assert.same(uri.toString(), source); - }, - - "/file.ext" : function () { - var source = "/file.ext"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "", "file.ext" ] - }); - - assert.same(uri.toString(), source); - }, - - "/?query" : function () { - var source = "/?query"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "" ], - query : { - query : "" - } - }); - - assert.same(uri.toString(), source); - }, - - "/?query=1&test=2#anchor" : function () { - var source = "/?query=1&test=2#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "" ], - query : { - query : "1", - test : "2" - }, - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "#anchor" : function () { - var source = "#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "path/to/file" : function () { - var source = "path/to/file"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "path", "to", "file" ] - }); - - assert.same(uri.toString(), source); - }, - - "localhost" : function () { - var source = "localhost"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "localhost" ] - }); - - assert.same(uri.toString(), source); - }, - - "192.168.1.1" : function () { - var source = "192.168.1.1"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "192.168.1.1" ] - }); - - assert.same(uri.toString(), source); - }, - - "host.com" : function () { - var source = "host.com"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "host.com" ] - }); - - assert.same(uri.toString(), source); - }, - - "//host.com:81" : function () { - var source = "host.com:81"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol : "host.com", - path : [ "81" ] - }); - - assert.same(uri.toString(), source); - }, - - "//host.com:81/" : function () { - var source = "host.com:81/"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol : "host.com", - path : [ "81", "" ] - }); - - assert.same(uri.toString(), source); - }, - - "host.com?query" : function () { - var source = "host.com?query"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "host.com" ], - query : { - query : "" - } - }); - - assert.same(uri.toString(), source); - }, - - "host.com#anchor" : function () { - var source = "host.com#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "host.com" ], - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "host.com/" : function () { - var source = "host.com/"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "host.com", "" ] - }); - - assert.same(uri.toString(), source); - }, - - "host.com/file.ext" : function () { - var source = "host.com/file.ext"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "host.com", "file.ext" ] - }); - - assert.same(uri.toString(), source); - }, - - "host.com/directory/?query" : function () { - var source = "host.com/directory/?query"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "host.com", "directory", "" ], - query : { - query : "" - } - }); - - assert.same(uri.toString(), source); - }, - - "host.com/directory/#anchor" : function () { - var source = "host.com/directory/#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "host.com", "directory", "" ], - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "host.com/directory/file.ext" : function () { - var source = "host.com/directory/file.ext"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "host.com", "directory", "file.ext" ] - }); - - assert.same(uri.toString(), source); - }, - - "//host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { - var source = "host.com:81/direc.tory/file.ext?query=1&test=2#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol : "host.com", - path : [ "81", "direc.tory", "file.ext" ], - query : { - query : "1", - test : "2" - }, - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "user@host.com" : function () { - var source = "user@host.com"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "user@host.com" ] - }); - - assert.same(uri.toString(), source); - }, - - "//user@host.com:81" : function () { - var source = "user@host.com:81"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol : "user@host.com", - path : [ "81" ] - }); - - assert.same(uri.toString(), source); - }, - - "user@host.com/" : function () { - var source = "user@host.com/"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "user@host.com", "" ] - }); - - assert.same(uri.toString(), source); - }, - - "user@host.com/file.ext" : function () { - var source = "user@host.com/file.ext"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "user@host.com", "file.ext" ] - }); - - assert.same(uri.toString(), source); - }, - - "user@host.com?query" : function () { - var source = "user@host.com?query"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "user@host.com" ], - query : { - query : "" - } - }); - - assert.same(uri.toString(), source); - }, - - "user@host.com#anchor" : function () { - var source = "user@host.com#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - path : [ "user@host.com" ], - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - }, - - "//user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor" : function () { - var source = "user:pass@host.com:81/direc.tory/file.ext?query=1&test=2#anchor"; - var uri = URI(source); - - assert.match(uri, { - source : source, - protocol : "user:", - path : [ "pass@host.com:81", "direc.tory", "file.ext" ], - anchor : "anchor" - }); - - assert.same(uri.toString(), source); - } - }); - }); -}); \ No newline at end of file From 7b16a08d0f835e697e854c2cf9214c8646161c49 Mon Sep 17 00:00:00 2001 From: Mikael Karon Date: Fri, 3 Aug 2012 17:40:06 +0800 Subject: [PATCH 43/43] updated VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 238cb5c..ee90284 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.3+ +1.0.4