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
|
|
|
|
2015-09-26 06:09:58 +03:00
|
|
|
"use strict";
|
|
|
|
|
2015-10-10 18:09:28 +03:00
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
|
|
|
const BrowserLoaderModule = {};
|
2015-10-14 02:18:43 +03:00
|
|
|
Cu.import("resource://devtools/client/shared/browser-loader.js", BrowserLoaderModule);
|
|
|
|
const { require } = BrowserLoaderModule.BrowserLoader("resource://devtools/client/memory/", this);
|
2015-09-26 06:09:58 +03:00
|
|
|
const { Task } = require("resource://gre/modules/Task.jsm");
|
2015-10-10 18:09:28 +03:00
|
|
|
const { createFactory, createElement, render } = require("devtools/client/shared/vendor/react");
|
|
|
|
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-09-26 06:09:58 +03:00
|
|
|
|
|
|
|
/**
|
2015-10-15 09:13:17 +03:00
|
|
|
* The current target, toolbox, MemoryFront, and HeapAnalysesClient, set by this tool's host.
|
2015-09-26 06:09:58 +03:00
|
|
|
*/
|
2015-10-15 09:13:17 +03:00
|
|
|
var gToolbox, gTarget, gFront, gHeapAnalysesClient;
|
2015-10-10 18:09:28 +03:00
|
|
|
|
2015-10-28 17:47:53 +03:00
|
|
|
/**
|
|
|
|
* Variables set by `initialize()`
|
|
|
|
*/
|
|
|
|
var gStore, unsubscribe, isHighlighted;
|
|
|
|
|
2015-09-26 06:09:58 +03:00
|
|
|
function initialize () {
|
2015-10-10 18:09:28 +03:00
|
|
|
return Task.spawn(function*() {
|
2015-10-28 15:09:57 +03:00
|
|
|
let root = document.querySelector("#app");
|
2015-10-28 17:47:53 +03:00
|
|
|
gStore = Store();
|
2015-10-28 22:59:53 +03:00
|
|
|
let app = createElement(App, { toolbox: gToolbox, front: gFront, heapWorker: gHeapAnalysesClient });
|
2015-10-28 17:47:53 +03:00
|
|
|
let provider = createElement(Provider, { store: gStore }, app);
|
2015-10-28 15:09:57 +03:00
|
|
|
render(provider, root);
|
2015-10-28 17:47:53 +03:00
|
|
|
unsubscribe = gStore.subscribe(onStateChange);
|
2015-09-26 06:09:58 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function destroy () {
|
2015-10-28 17:47:53 +03:00
|
|
|
return Task.spawn(function*(){
|
|
|
|
unsubscribe();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fired on any state change, currently only handles toggling
|
|
|
|
* the highlighting of the tool when recording allocations.
|
|
|
|
*/
|
|
|
|
function onStateChange () {
|
|
|
|
let isRecording = gStore.getState().allocations.recording;
|
|
|
|
|
|
|
|
if (isRecording !== isHighlighted) {
|
|
|
|
isRecording ?
|
|
|
|
gToolbox.highlightTool("memory") :
|
|
|
|
gToolbox.unhighlightTool("memory");
|
|
|
|
isHighlighted = isRecording;
|
|
|
|
}
|
2015-09-26 06:09:58 +03:00
|
|
|
}
|