Bug 1378817 - Stop using sdk/lang/functional in DevTools. r=jdescottes
MozReview-Commit-ID: CXMu5a0KNGT
--- a/devtools/client/memory/components/tree-map/canvas-utils.js
+++ b/devtools/client/memory/components/tree-map/canvas-utils.js
@@ -10,17 +10,17 @@
* Create 2 canvases and contexts for drawing onto, 1 main canvas, and 1 zoom
* canvas. The main canvas dimensions match the parent div, but the CSS can be
* transformed to be zoomed and dragged around (potentially creating a blurry
* canvas once zoomed in). The zoom canvas is a zoomed in section that matches
* the parent div's dimensions and is kept in place through CSS. A zoomed in
* view of the visualization is drawn onto this canvas, providing a crisp zoomed
* in view of the tree map.
*/
-const { debounce } = require("sdk/lang/functional");
+const { debounce } = require("devtools/shared/debounce");
const EventEmitter = require("devtools/shared/event-emitter");
const HTML_NS = "http://www.w3.org/1999/xhtml";
const FULLSCREEN_STYLE = {
width: "100%",
height: "100%",
position: "absolute",
};
--- a/devtools/client/memory/components/tree-map/drag-zoom.js
+++ b/devtools/client/memory/components/tree-map/drag-zoom.js
@@ -1,15 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
-const { debounce } = require("sdk/lang/functional");
+const { debounce } = require("devtools/shared/debounce");
const { lerp } = require("devtools/client/memory/utils");
const EventEmitter = require("devtools/shared/event-emitter");
const LERP_SPEED = 0.5;
const ZOOM_SPEED = 0.01;
const TRANSLATE_EPSILON = 1;
const ZOOM_EPSILON = 0.001;
const LINE_SCROLL_MODE = 1;
--- a/devtools/client/webaudioeditor/views/context.js
+++ b/devtools/client/webaudioeditor/views/context.js
@@ -1,16 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/* import-globals-from ../includes.js */
-const { debounce } = require("sdk/lang/functional");
+const { debounce } = require("devtools/shared/debounce");
const flags = require("devtools/shared/flags");
// Globals for d3 stuff
// Default properties of the graph on rerender
const GRAPH_DEFAULTS = {
translate: [20, 20],
scale: 1
};
new file mode 100644
--- /dev/null
+++ b/devtools/shared/debounce.js
@@ -0,0 +1,39 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+/**
+ * From underscore's `_.debounce`
+ * http://underscorejs.org
+ * (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
+ * Underscore may be freely distributed under the MIT license.
+ *
+ * [and in turn extracted from "sdk/lang/functional/concurrent.js"]
+ */
+exports.debounce = function (fn, wait) {
+ let timeout, args, context, timestamp, result;
+
+ let later = function () {
+ let last = Date.now() - timestamp;
+ if (last < wait) {
+ timeout = setTimeout(later, wait - last);
+ } else {
+ timeout = null;
+ result = fn.apply(context, args);
+ context = args = null;
+ }
+ };
+
+ return function (...aArgs) {
+ context = this;
+ args = aArgs;
+ timestamp = Date.now();
+ if (!timeout) {
+ timeout = setTimeout(later, wait);
+ }
+
+ return result;
+ };
+};
--- a/devtools/shared/moz.build
+++ b/devtools/shared/moz.build
@@ -41,16 +41,17 @@ XPCSHELL_TESTS_MANIFESTS += ['tests/unit
JAR_MANIFESTS += ['jar.mn']
DevToolsModules(
'async-storage.js',
'async-utils.js',
'builtin-modules.js',
'content-observer.js',
+ 'debounce.js',
'defer.js',
'deprecated-sync-thenables.js',
'DevToolsUtils.js',
'dom-node-constants.js',
'dom-node-filter-constants.js',
'event-emitter.js',
'extend.js',
'flags.js',