From 8fe92b94ce5e1e2857d088752d94e19db7e3d8a8 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Sun, 17 Jun 2012 22:31:44 -0700 Subject: montage v11 merge into ninja Signed-off-by: Valerio Virgillito --- node_modules/montage/core/core.js | 14 +----- node_modules/montage/core/deserializer.js | 64 +++++++++++++++--------- node_modules/montage/core/event/mutable-event.js | 61 +--------------------- node_modules/montage/core/promise.js | 42 ++++++++++------ node_modules/montage/core/serializer.js | 4 +- 5 files changed, 71 insertions(+), 114 deletions(-) (limited to 'node_modules/montage/core') diff --git a/node_modules/montage/core/core.js b/node_modules/montage/core/core.js index 26733c94..9109b772 100755 --- a/node_modules/montage/core/core.js +++ b/node_modules/montage/core/core.js @@ -635,16 +635,4 @@ Object.defineProperty(Montage, "callDelegateMethod", { return delegateFunction.apply(delegate, arguments); } } -}); - -// XXX Does not presently function server-side -if (typeof window !== "undefined") { - - var EventManager = require("core/event/event-manager").EventManager; - EventManager.create().initWithWindow(window); - - // Now that we have a defaultEventManager we can setup the bindings system - require("core/event/binding"); - -} - +}); \ No newline at end of file diff --git a/node_modules/montage/core/deserializer.js b/node_modules/montage/core/deserializer.js index 86cdc560..424a2bc9 100755 --- a/node_modules/montage/core/deserializer.js +++ b/node_modules/montage/core/deserializer.js @@ -31,7 +31,7 @@ try { @class module:montage/core/deserializer.Deserializer @extends module:montage/core/core.Montage */ -var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deserializer.Deserializer# */ { +var Deserializer = exports.Deserializer = Montage.create(Montage, /** @lends module:montage/core/deserializer.Deserializer# */ { _MONTAGE_ID_ATTRIBUTE: {value: "data-montage-id"}, _objects: {value: null}, @@ -533,7 +533,7 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri var serialization = this._serialization, moduleIds = this._requiredModuleIds = [], modules = this._modules, - desc, moduleId, name, objectLocation; + desc, moduleId; for (var label in serialization) { desc = serialization[label]; @@ -542,16 +542,8 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri if ("module" in desc) { moduleId = desc.module; } else if ("prototype" in desc || "object" in desc) { - name = desc.prototype || desc.object - objectLocation = name.split("["); - moduleId = objectLocation[0]; - desc.module = moduleId; - if (objectLocation.length == 2) { - desc.name = objectLocation[1].slice(0, -1); - } else { - this._findObjectNameRegExp.test(moduleId); - desc.name = RegExp.$1.replace(this._toCamelCaseRegExp, this._replaceToCamelCase); - } + Deserializer.parseForModuleAndName(desc.prototype || desc.object, desc); + moduleId = desc.module; } if (moduleId && !modules[moduleId] && moduleIds.indexOf(moduleId) == -1) { @@ -559,6 +551,34 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri } } }}, + + /** + Sets the module loader used during deserialization. + @function + @param {String} name The string representing a module/name pair, such as "my-module[MyModule]". + @param {Object} description The description object on which the parseForModuleAndName will populate the module and name properties. [Optional] + @returns {Object} The description object with module and name properties populated. + */ + parseForModuleAndName: { + value: function(name, desc) { + var bracketIndex; + + if (typeof desc === "undefined") { + desc = {}; + } + bracketIndex = name.indexOf("["); + if (bracketIndex > 0) { + desc.module = name.substr(0, bracketIndex); + desc.name = name.slice(bracketIndex+1, -1); + } else { + desc.module = name; + Deserializer._findObjectNameRegExp.test(name); + desc.name = RegExp.$1.replace(Deserializer._toCamelCaseRegExp, Deserializer._replaceToCamelCase); + } + return desc; + } + }, + /** @private */ @@ -680,23 +700,25 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri hasObject = object != null, counter, descString, - objectLocation; + objectLocation, + bracketIndex; if ("module" in desc) { moduleId = desc.module; objectName = name = desc.name; } else if ("prototype" in desc || "object" in desc) { - objectLocation = (desc.prototype || desc.object).split("["); + bracketIndex = (desc.prototype || desc.object).indexOf("["); // this code is actually only used when canEval == false, // module+name are added when the modules are parsed but it's // slow to redo the _serializationString in order to keep the // added module+name when we do JSON.parse(_serializationString) // at canEval == false. - moduleId = objectLocation[0]; - if (objectLocation.length == 2) { - objectName = name = objectLocation[1].slice(0, -1); + if (bracketIndex > 0) { + moduleId = name.substr(0, bracketIndex); + objectName = name = name.slice(bracketIndex+1, -1); } else { - self._findObjectNameRegExp.test(moduleId); + moduleId = name; + self._findObjectNameRegExp.test(name); objectName = name = RegExp.$1.replace(self._toCamelCaseRegExp, function(_, g1) { return g1.toUpperCase() }); } } @@ -1142,8 +1164,4 @@ function deserialize(serialization, require, origin) { return deferred.promise; } -if (typeof exports !== "undefined") { - exports.Deserializer = Deserializer; - exports.deserialize = deserialize; -} - +exports.deserialize = deserialize; diff --git a/node_modules/montage/core/event/mutable-event.js b/node_modules/montage/core/event/mutable-event.js index 6f6a0cfd..2ffe2a37 100755 --- a/node_modules/montage/core/event/mutable-event.js +++ b/node_modules/montage/core/event/mutable-event.js @@ -6,18 +6,13 @@ /** @module montage/core/event/mutable-event @requires montage - @requires montage/core/enum */ -var Montage = require("montage").Montage, - Enum = require("core/enum").Enum; +var Montage = require("montage").Montage; // XXX Does not presently function server-side if (typeof window !== "undefined") { -var ChangeTypes = exports.ChangeTypes = Enum.create().initWithMembers("MODIFICATION", "ADDITION", "REMOVAL"); - var _eventConstructorsByType = {}; -var _changeEventConstructor = null; var nullDescriptor = {value: null}; var wrapProperty = function(obj, key) { @@ -84,44 +79,6 @@ var MutableEvent = exports.MutableEvent = Montage.create(Montage,/** @lends modu } }, - /** - @function - @returns new _changeEventConstructor() - */ - changeEvent: { - value: function() { - return new _changeEventConstructor(); - } - }, - -/** - @function - @param {Event} key TODO - @param {Event} minus TODO - @returns changeEvent - */ - changeEventForKeyAndValue: { - value: function(key, minus) { - var changeEvent = new _changeEventConstructor(); - changeEvent.type = "change@" + key; - changeEvent.minus = minus; - changeEvent.plus = undefined; - changeEvent.propertyChange = ChangeTypes.MODIFICATION; - return changeEvent; - } - }, - - /** - @function - @param {String} plus TODO - @returns itself - */ - withPlusValue: { - value: function(plus) { - this.plus = plus; - return this; - } - }, /** @private */ @@ -220,21 +177,5 @@ var MutableEvent = exports.MutableEvent = Montage.create(Montage,/** @lends modu } }); -/** - @private -*/ -_changeEventConstructor = function() { -}; -/** - @private -*/ -_changeEventConstructor.prototype = MutableEvent.create()._initPrototypeWithEvent(document.createEvent("CustomEvent").initCustomEvent("change", true, false, null)); -// TODO this shouldn't be necessary; initWithCustomEvent should be setting the type to "change" but that doesn't seem to be the case -// TODO should file a bug on this with some test reduction -/** - @private -*/ -_changeEventConstructor.prototype.type = "change"; -exports._Change = _changeEventConstructor; } // client-side diff --git a/node_modules/montage/core/promise.js b/node_modules/montage/core/promise.js index 7563a742..6477131d 100755 --- a/node_modules/montage/core/promise.js +++ b/node_modules/montage/core/promise.js @@ -263,6 +263,7 @@ var PrimordialPromise = Creatable.create({ self.Promise = this; rejections.push(self); errors.push(error ? (error.stack ? error.stack : error) : reason); + displayErrors(); return self; } }, @@ -676,22 +677,31 @@ var Promise = PrimordialPromise.create({}, { // Descriptor for each of the three var rejections = []; var errors = []; -// Live console objects are not handled on tablets -if (typeof window !== "undefined" && !window.Touch) { - - /* - * This promise library consumes exceptions thrown in callbacks so - * that they can be handled asynchronously. The exceptions get - * added to ``errors`` when they are consumed, and removed when - * they are handled. In many debuggers, the view of the reported - * array will update to reflect its current contents so you can - * always see if you have missed an error. - * - * This log will appear once for every time this module gets - * instantiated. That should be once per frame. - */ - console.log("Should be empty:", errors); -} +var errorsDisplayed = false; +var displayErrors = function () { + // Live console objects are not handled on tablets or in Node + if ( + !errorsDisplayed && + typeof window !== "undefined" && + !window.Touch && + typeof console === "object" + ) { + + /* + * This promise library consumes exceptions thrown in callbacks so + * that they can be handled asynchronously. The exceptions get + * added to ``errors`` when they are consumed, and removed when + * they are handled. In many debuggers, the view of the reported + * array will update to reflect its current contents so you can + * always see if you have missed an error. + * + * This log will appear once for every time this module gets + * instantiated. That should be once per frame. + */ + console.log("Should be empty:", errors); + errorsDisplayed = true; + } +}; exports.Promise = Promise; diff --git a/node_modules/montage/core/serializer.js b/node_modules/montage/core/serializer.js index 72543328..deadbc68 100755 --- a/node_modules/montage/core/serializer.js +++ b/node_modules/montage/core/serializer.js @@ -529,10 +529,10 @@ var Serializer = Montage.create(Montage, /** @lends module:montage/serializer.Se return this._serializeElement(value); } else if (Array.isArray(value)) { return this._serializeArray(value, indent + 1); - } else if (Object.getPrototypeOf(value) === Object.prototype) { - return this._serializeObjectLiteral(value, null, indent + 1); } else if (value.constructor === Function) { return this._serializeFunction(value, indent); + } else if (!("getInfoForObject" in value)) { // we consider object literals the ones who aren't a Montage object + return this._serializeObjectLiteral(value, null, indent + 1); } else { // TODO: should refactor this to handle references here, doesn't make // sense to wait until it hits _serializeObject for that to happen -- cgit v1.2.3