Bug 1378817 - Stop using sdk/lang/functional in DevTools. r=jdescottes
authorsole <sole@mozilla.com>
Thu, 20 Jul 2017 17:57:28 +0100
changeset 418875 8baab0d7ec0313915cb5225404755c92a7f0fcb4
parent 418874 8949e22b8033cc1e59622a742b282725586d1556
child 418876 f1823b0526565139b7d01822d1fc2c6200557b31
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1378817
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1378817 - Stop using sdk/lang/functional in DevTools. r=jdescottes MozReview-Commit-ID: CXMu5a0KNGT
devtools/client/memory/components/tree-map/canvas-utils.js
devtools/client/memory/components/tree-map/drag-zoom.js
devtools/client/webaudioeditor/views/context.js
devtools/shared/debounce.js
devtools/shared/moz.build
--- 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',