dom-view.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. // React & Redux
  7. const React = require("devtools/client/shared/vendor/react");
  8. const ReactDOM = require("devtools/client/shared/vendor/react-dom");
  9. const { Provider } = require("devtools/client/shared/vendor/react-redux");
  10. const { combineReducers } = require("devtools/client/shared/vendor/redux");
  11. // DOM Panel
  12. const MainFrame = React.createFactory(require("./components/main-frame"));
  13. // Store
  14. const createStore = require("devtools/client/shared/redux/create-store")({
  15. log: false
  16. });
  17. const { reducers } = require("./reducers/index");
  18. const store = createStore(combineReducers(reducers));
  19. /**
  20. * This object represents view of the DOM panel and is responsible
  21. * for rendering the content. It renders the top level ReactJS
  22. * component: the MainFrame.
  23. */
  24. function DomView(localStore) {
  25. addEventListener("devtools/chrome/message",
  26. this.onMessage.bind(this), true);
  27. // Make it local so, tests can access it.
  28. this.store = localStore;
  29. }
  30. DomView.prototype = {
  31. initialize: function (rootGrip) {
  32. let content = document.querySelector("#content");
  33. let mainFrame = MainFrame({
  34. object: rootGrip,
  35. });
  36. // Render top level component
  37. let provider = React.createElement(Provider, {
  38. store: this.store
  39. }, mainFrame);
  40. this.mainFrame = ReactDOM.render(provider, content);
  41. },
  42. onMessage: function (event) {
  43. let data = event.data;
  44. let method = data.type;
  45. if (typeof this[method] == "function") {
  46. this[method](data.args);
  47. }
  48. },
  49. };
  50. // Construct DOM panel view object and expose it to tests.
  51. // Tests can access it throught: |panel.panelWin.view|
  52. window.view = new DomView(store);