Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. const React = require('react');
  2. const ReactDOM = require('react-dom');
  3.  
  4. class PanelController {
  5. constructor(App) {
  6. this.App = App;
  7. this.instance = null;
  8. this.rootNode = document.createElement('div');
  9. this.attachment = null;
  10.  
  11. ['show', 'hide', 'update'].forEach((fn) =>
  12. this[fn] = this[fn].bind(this)
  13. );
  14. }
  15.  
  16. show(event) {
  17. const { selection, root } = require('scenegraph');
  18. const App = this.App;
  19.  
  20. this.attachment = event.node;
  21. this.attachment.appendChild(this.rootNode);
  22.  
  23. if (!this.instance) {
  24. this.instance = ReactDOM.render(<App />, this.rootNode);
  25. }
  26.  
  27. this.update(selection, root);
  28. }
  29.  
  30. hide(event) {
  31. this.attachment.removeChild(this.rootNode);
  32. }
  33.  
  34. update(selection, root) {
  35. if (this.instance.documentStateChanged) {
  36. this.instance.documentStateChanged(selection, root);
  37. }
  38. }
  39. }
  40.  
  41. module.exports = PanelController;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement