debugger icon indicating copy to clipboard operation
debugger copied to clipboard

Framework Features

Open jasonLaster opened this issue 9 years ago • 21 comments

  • [x] 1. Highlighting framework frames in the call stack. More work to do here.
  • [ ] 2. Show component names in the call stack. React team excited about this. Right now we show filenames. They want to map it to something semantic to the framework. Would be unique. #3792
  • [x] 3. Showing framework components in the source tree.
  • [x] 4. Previewing library objects on hover. Custom formatters with a nice navigation UI. (Sam)
  • [x] 5. Show component instances in the sidebar. New pane showing all instances of a component.

jasonLaster avatar Aug 28 '17 14:08 jasonLaster

5. Show component instances in the sidebar. New pane showing all instances of a component.


diff --git a/src/components/SecondaryPanes/index.js b/src/components/SecondaryPanes/index.js
index a801f64..8afc2e5 100644
--- a/src/components/SecondaryPanes/index.js
+++ b/src/components/SecondaryPanes/index.js
@@ -142,6 +142,26 @@ class SecondaryPanes extends Component<Props> {
     ];
   }
 
+  getComponentItem() {
+    if (!sourceMetaData.isReactComponent) {
+      return null;
+    }
+
+    const componentName = //borrow preview's extra field which has the displayName
+    const preview = // borrow what the preview does w/ the Object Inspector
+
+    return {
+      header: componentName
+      className: "scopes-pane",
+      component: preview,
+      opened: prefs.scopesVisible,
+      onToggle: opened => {
+        prefs.scopesVisible = opened;
+      },
+      shouldOpen: isPaused
+    };
+  }
+
   getScopeItem() {
     const isPaused = () => !!this.props.pauseData;
 
@@ -243,6 +263,10 @@ class SecondaryPanes extends Component<Props> {
     const items: Array<SecondaryPanesItems> = [];
 
     if (!this.props.horizontal) {
+      items.unshift(this.getComponentItem());
+    }
+
+    if (!this.props.horizontal) {
       items.unshift(this.getScopeItem());
     }
 

Screen Shot 2017-11-10 at 7.23.11 PM.png

jasonLaster avatar Nov 11 '17 00:11 jasonLaster

It's absolutely okay to have several ppl working on it as long as we're talking and sharing what we learn :)

jasonLaster avatar Nov 11 '17 17:11 jasonLaster

I am trying to finish the 5th.

decadef20 avatar Nov 12 '17 15:11 decadef20

here are some notes on how we get the react preview.

diff --git a/src/components/Editor/Preview/Popup.js b/src/components/Editor/Preview/Popup.js
index 89c0177..abca23b 100644
--- a/src/components/Editor/Preview/Popup.js
+++ b/src/components/Editor/Preview/Popup.js
@@ -39,6 +39,8 @@ type Props = {
   extra: string
 };
 
+// This is how we see if it is a react component
+// we can move this method to a better spot :)
 function isReactComponent(roots) {
   return roots.some(root => root.name === "_reactInternalInstance");
 }
@@ -113,6 +115,8 @@ export class Popup extends Component<Props> {
       return null;
     }
 
+    // This is where we render the React Preview
+    // note that the extra field has the display name
     if (isReactComponent(roots)) {
       if (typeof extra !== "undefined") {
         reactHeader = (
@@ -122,6 +126,11 @@ export class Popup extends Component<Props> {
         );
       }
 
+      // all we do at the moment is filter the component's fields
+      // so that it has ["state", "props"]... in the future we'll want to do more here
+      // also we might want to show the non-react props which sometimes exists
+      // e.g. if you have a dropdown component, you might set `this.button` ...
+      //and we'd want to show button in the preview but i digress :P
       roots = roots.filter(r => ["state", "props"].includes(r.name));
     }
 

and a sketch for a new FrameworkComponent file that we can render from the sidebar

/* 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/>. */

// @flow

function isReactComponent() {
  // copy from Popup
}

type Props = {};

class FrameworkComponent extends Component<Props> {
  renderReactComponent() {
    const { pause, frame } = this.props;

    // we want to get the `this` object from the pause or frame object, can't remember what
    const roots = // find this in pause or frame :)
      // roots are the roots for the object inspector

      // copying the code from Popup.js
      (roots = roots.filter(r => ["state", "props"].includes(r.name)));
    return this.renderObjectInspector(roots);

    // NOTE i haven't gotten the displayName of the react component here
    // because it will be shown in the accordion header
  }

  render() {
    if (isReactComponent()) {
      return this.renderReactComponent();
    }
  }
}

FrameworkComponent.contextTypes = {
  shortcuts: PropTypes.object
};

export default connect(
  state => {
    return {
      pause: getPause(state),
      frame: getSelectedFrame(state)
    };
  },
  dispatch => bindActionCreators(actions, dispatch)
)(FrameworkComponent);

jasonLaster avatar Nov 12 '17 16:11 jasonLaster

/claim

tobmaster avatar Nov 14 '17 15:11 tobmaster

Thanks for claiming the issue! :wave:

!!! Please check your email and confirm the invitation

Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.

:fox_face: Debugger team!

claim avatar Nov 14 '17 15:11 claim

hi I would like to help me with 5th one

varenya avatar Nov 14 '17 17:11 varenya

Great @varenya! Jump in and communicate progress

jasonLaster avatar Nov 14 '17 18:11 jasonLaster

@tobmaster how has the hacking been?

jasonLaster avatar Nov 14 '17 18:11 jasonLaster

@jasonLaster sure thanks I will go through the docs and reach out if any help needed thanks :)

varenya avatar Nov 15 '17 08:11 varenya

@jasonLaster I started learning the codebase and talked with @amitzur we both had the issue that also the popup dialog was not working (cause the value passed to the popup is {type:undefined}). Yesterday we haven't seen why it is like that. Afaik Amit wanted to look into that and I wanted to have a look too.

tobmaster avatar Nov 15 '17 09:11 tobmaster

Thanks @tobmaster, that's not good :)

mind sharing an STR. @samuel-peers worked on adding extra so we could see the DisplayName

jasonLaster avatar Nov 15 '17 14:11 jasonLaster

I'll take a look

samuel-peers avatar Nov 15 '17 22:11 samuel-peers

I will stop working on this since already few people are working and I got a another issue recommended on slack so I will be going for that.

varenya avatar Nov 16 '17 10:11 varenya

@varenya feel free to keep hacking on this one too. it's big enough to warrant many eyes

jasonLaster avatar Nov 16 '17 14:11 jasonLaster

Didn't had the chance to work on this that much yet so i better unclaim for now

tobmaster avatar Nov 19 '17 17:11 tobmaster

/unclaim

tobmaster avatar Nov 19 '17 17:11 tobmaster

/claim

mmcote avatar Jan 24 '18 02:01 mmcote

Thanks for claiming the issue! :wave:

Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.

:fox_face: Debugger team!

claim avatar Jan 24 '18 02:01 claim

^^^5

mmcote avatar Jan 24 '18 02:01 mmcote