2015-09-26 06:09:58 +03:00
|
|
|
/* 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/. */
|
2015-10-20 20:59:47 +03:00
|
|
|
|
2016-12-21 17:21:24 +03:00
|
|
|
/* exported initialize, destroy */
|
|
|
|
|
2015-09-26 06:09:58 +03:00
|
|
|
"use strict";
|
|
|
|
|
2016-12-21 17:21:24 +03:00
|
|
|
const { utils: Cu } = Components;
|
2015-10-10 18:09:28 +03:00
|
|
|
const BrowserLoaderModule = {};
|
2015-10-14 02:18:43 +03:00
|
|
|
Cu.import("resource://devtools/client/shared/browser-loader.js", BrowserLoaderModule);
|
2016-03-09 04:21:11 +03:00
|
|
|
const { require } = BrowserLoaderModule.BrowserLoader({
|
|
|
|
baseURI: "resource://devtools/client/memory/",
|
2016-09-21 18:07:02 +03:00
|
|
|
window
|
2016-03-09 04:21:11 +03:00
|
|
|
});
|
2016-05-17 22:07:55 +03:00
|
|
|
const { Task } = require("devtools/shared/task");
|
2015-10-30 17:06:52 +03:00
|
|
|
const { createFactory, createElement } = require("devtools/client/shared/vendor/react");
|
|
|
|
const ReactDOM = require("devtools/client/shared/vendor/react-dom");
|
2015-10-10 18:09:28 +03:00
|
|
|
const { Provider } = require("devtools/client/shared/vendor/react-redux");
|
|
|
|
const App = createFactory(require("devtools/client/memory/app"));
|
|
|
|
const Store = require("devtools/client/memory/store");
|
2015-10-29 08:46:25 +03:00
|
|
|
const { assert } = require("devtools/shared/DevToolsUtils");
|
2015-09-26 06:09:58 +03:00
|
|
|
|
|
|
|
/**
|
2016-12-21 17:21:24 +03:00
|
|
|
* The current target, toolbox, MemoryFront, and HeapAnalysesClient,
|
|
|
|
* set by this tool's host.
|
2015-09-26 06:09:58 +03:00
|
|
|
*/
|
2016-12-21 17:21:24 +03:00
|
|
|
var gToolbox, gFront, gHeapAnalysesClient;
|
2015-10-10 18:09:28 +03:00
|
|
|
|
2015-10-28 17:47:53 +03:00
|
|
|
/**
|
|
|
|
* Variables set by `initialize()`
|
|
|
|
*/
|
2016-12-21 17:21:24 +03:00
|
|
|
var gStore, gRoot, gApp, gProvider, unsubscribe, isHighlighted;
|
2015-10-28 17:47:53 +03:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
var initialize = Task.async(function* () {
|
2015-10-29 08:46:25 +03:00
|
|
|
gRoot = document.querySelector("#app");
|
|
|
|
gStore = Store();
|
2016-12-21 17:21:24 +03:00
|
|
|
gApp = createElement(App,
|
|
|
|
{ toolbox: gToolbox, front: gFront, heapWorker: gHeapAnalysesClient });
|
2015-10-29 08:46:25 +03:00
|
|
|
gProvider = createElement(Provider, { store: gStore }, gApp);
|
2015-10-30 17:06:52 +03:00
|
|
|
ReactDOM.render(gProvider, gRoot);
|
2015-10-29 08:46:25 +03:00
|
|
|
unsubscribe = gStore.subscribe(onStateChange);
|
|
|
|
});
|
2015-09-26 06:09:58 +03:00
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
var destroy = Task.async(function* () {
|
2015-10-30 17:06:52 +03:00
|
|
|
const ok = ReactDOM.unmountComponentAtNode(gRoot);
|
2015-10-29 08:46:25 +03:00
|
|
|
assert(ok, "Should successfully unmount the memory tool's top level React component");
|
|
|
|
|
|
|
|
unsubscribe();
|
|
|
|
|
2016-12-21 17:21:24 +03:00
|
|
|
gStore = gRoot = gApp = gProvider = unsubscribe = isHighlighted = null;
|
2015-10-29 08:46:25 +03:00
|
|
|
});
|
2015-10-28 17:47:53 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fired on any state change, currently only handles toggling
|
|
|
|
* the highlighting of the tool when recording allocations.
|
|
|
|
*/
|
2016-05-17 21:25:54 +03:00
|
|
|
function onStateChange() {
|
2015-10-28 17:47:53 +03:00
|
|
|
let isRecording = gStore.getState().allocations.recording;
|
2015-10-29 08:46:25 +03:00
|
|
|
if (isRecording === isHighlighted) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-28 17:47:53 +03:00
|
|
|
|
2015-10-29 08:46:25 +03:00
|
|
|
if (isRecording) {
|
|
|
|
gToolbox.highlightTool("memory");
|
|
|
|
} else {
|
|
|
|
gToolbox.unhighlightTool("memory");
|
2015-10-28 17:47:53 +03:00
|
|
|
}
|
2015-10-29 08:46:25 +03:00
|
|
|
|
|
|
|
isHighlighted = isRecording;
|
2015-09-26 06:09:58 +03:00
|
|
|
}
|