From 46d05b1191d2035657ca3bd3dc24967b4706bd74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Mon, 15 Jul 2013 21:04:43 -0700 Subject: [PATCH] Sync vendor modules from FB. Biggest win here is that we'll strip out the console.error from EventListener and we won't need to suggest people use a console polyfill with the minified build. --- src/vendor/core/$.js | 22 +++++++++++----------- src/vendor/core/emptyFunction.js | 9 +-------- src/vendor/core/hasArrayNature.js | 5 ++++- src/vendor/core/requestAnimationFrame.js | 20 +++++++++++--------- src/vendor/stubs/EventListener.js | 12 +++++++----- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/vendor/core/$.js b/src/vendor/core/$.js index 5846156c55..95d63cf0bf 100644 --- a/src/vendor/core/$.js +++ b/src/vendor/core/$.js @@ -14,11 +14,16 @@ * limitations under the License. * * @providesModule $ + * @typechecks */ var ge = require('ge'); +var ex = require('ex'); /** + * @param {string|DOMDocument|DOMElement|DOMTextNode} id + * @return {DOMDocument|DOMElement|DOMTextNode} + * * Find a node by ID. * * If your application code depends on the existence of the element, use $, @@ -27,18 +32,13 @@ var ge = require('ge'); * If you're not sure whether or not the element exists, use ge instead, and * manually check for the element's existence in your application code. */ -function $(arg) { - var element = ge(arg); +function $(id) { + var element = ge(id); if (!element) { - if (typeof arg == 'undefined') { - arg = 'undefined'; - } else if (arg === null) { - arg = 'null'; - } - throw new Error( - 'Tried to get element "' + arg.toString() + '" but it is not present ' + - 'on the page.' - ); + throw new Error(ex( + 'Tried to get element with id of "%s" but it is not present on the page.', + id + )); } return element; } diff --git a/src/vendor/core/emptyFunction.js b/src/vendor/core/emptyFunction.js index 0263981c2a..3aa05f3252 100644 --- a/src/vendor/core/emptyFunction.js +++ b/src/vendor/core/emptyFunction.js @@ -37,14 +37,7 @@ copyProperties(emptyFunction, { thatReturnsTrue: makeEmptyFunction(true), thatReturnsNull: makeEmptyFunction(null), thatReturnsThis: function() { return this; }, - thatReturnsArgument: function(arg) { return arg; }, - mustImplement: function(module, property) { - return function() { - if (__DEV__) { - throw new Error(module + '.' + property + ' must be implemented!'); - } - }; - } + thatReturnsArgument: function(arg) { return arg; } }); module.exports = emptyFunction; diff --git a/src/vendor/core/hasArrayNature.js b/src/vendor/core/hasArrayNature.js index 802b462219..dd7b84157c 100644 --- a/src/vendor/core/hasArrayNature.js +++ b/src/vendor/core/hasArrayNature.js @@ -39,9 +39,12 @@ function hasArrayNature(obj) { ('length' in obj) && // not window !('setInterval' in obj) && + // no DOM node should be considered an array-like + // a 'select' element has 'length' and 'item' properties + (typeof obj.nodeType != 'number') && ( // a real array - Object.prototype.toString.call(obj) === "[object Array]" || + Array.isArray(obj) || // arguments ('callee' in obj) || // HTMLCollection/NodeList diff --git a/src/vendor/core/requestAnimationFrame.js b/src/vendor/core/requestAnimationFrame.js index e71052efbf..090949c29f 100644 --- a/src/vendor/core/requestAnimationFrame.js +++ b/src/vendor/core/requestAnimationFrame.js @@ -18,17 +18,19 @@ var emptyFunction = require('emptyFunction'); +var lastTime = 0; + var requestAnimationFrame = - window.requestAnimationFrame || - window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || - window.oRequestAnimationFrame || - window.msRequestAnimationFrame || + global.requestAnimationFrame || + global.webkitRequestAnimationFrame || + global.mozRequestAnimationFrame || + global.oRequestAnimationFrame || + global.msRequestAnimationFrame || function(callback) { - // Browsers which don't support requestAnimationFrame are likely running on - // older hardware, so it's not reasonable to expect 60FPS animations out of - // them. 30FPS (33.3ms per frame) is more reasonable. - return window.setTimeout(callback, 33); + var currTime = Date.now(); + var timeDelay = Math.max(0, 16 - (currTime - lastTime)); + lastTime = currTime + timeDelay; + return global.setTimeout(callback, timeDelay); }; // Works around a rare bug in Safari 6 where the first request is never invoked. diff --git a/src/vendor/stubs/EventListener.js b/src/vendor/stubs/EventListener.js index 19466e4209..04d691d60d 100644 --- a/src/vendor/stubs/EventListener.js +++ b/src/vendor/stubs/EventListener.js @@ -44,11 +44,13 @@ var EventListener = { */ capture: function(el, handlerBaseName, cb) { if (!el.addEventListener) { - console.error( - 'You are attempting to use addEventlistener ' + - 'in a browser that does not support it support it.' + - 'This likely means that you will not receive events that ' + - 'your application relies on (such as scroll).'); + if (__DEV__) { + console.error( + 'You are attempting to use addEventlistener ' + + 'in a browser that does not support it support it.' + + 'This likely means that you will not receive events that ' + + 'your application relies on (such as scroll).'); + } return; } else { el.addEventListener(handlerBaseName, cb, true);