1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* exported initialize, destroy, Promise */
12 } = require("resource://devtools/client/shared/vendor/react.js");
13 const ReactDOM = require("resource://devtools/client/shared/vendor/react-dom.js");
16 } = require("resource://devtools/client/shared/vendor/react-redux.js");
17 const App = createFactory(require("resource://devtools/client/memory/app.js"));
18 const Store = require("resource://devtools/client/memory/store.js");
19 const { assert } = require("resource://devtools/shared/DevToolsUtils.js");
23 } = require("resource://devtools/client/memory/actions/front.js");
25 // Shared variables used by several methods of this module.
26 let root, store, unsubscribe;
28 const initialize = async function (commands) {
29 // Exposed by panel.js
30 const { gToolbox, gHeapAnalysesClient } = window;
32 root = document.querySelector("#app");
34 const app = createElement(App, {
37 heapWorker: gHeapAnalysesClient,
39 const provider = createElement(Provider, { store }, app);
40 ReactDOM.render(provider, root);
41 unsubscribe = store.subscribe(onStateChange);
44 window.gStore = store;
47 const updateFront = front => {
48 store.dispatch(updateMemoryFront(front));
51 const destroy = function () {
52 const ok = ReactDOM.unmountComponentAtNode(root);
55 "Should successfully unmount the memory tool's top level React component"
65 * Fired on any state change, currently only handles toggling
66 * the highlighting of the tool when recording allocations.
68 function onStateChange() {
69 const { gToolbox } = window;
71 const isRecording = store.getState().allocations.recording;
72 if (isRecording === isHighlighted) {
77 gToolbox.highlightTool("memory");
79 gToolbox.unhighlightTool("memory");
82 isHighlighted = isRecording;
85 module.exports = { initialize, updateFront, destroy };