Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devtool): add react devtool support [WIP] #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Brahmos, { Suspense, lazy } from '../src';
// adding debug for react devtool support
import '../src/debug';

import TodoList from './TodoList';
import UseStateExample from './UseStateExample';
Expand Down
36 changes: 36 additions & 0 deletions src/debug/devtool/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export function initDevTools() {
// rdtHook -> React Devtools hook
const rdtHook = (window).__REACT_DEVTOOLS_GLOBAL_HOOK__;

// the developer has not installed react devtools
if(rdtHook == null) return;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when a person runs app in Development env, should we add a log recommending them to use React DevTools?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should add that


catchErrors(() => {
let isDev = false;

try {
isDev = process.env.NODE_ENV !== 'production';
}
catch {}

window.parent.postMessage({
source: 'react-devtools-detector',
reactBuildType: isDev
? 'development'
: 'production'
},
'*');
})();
}

function catchErrors(fn) {
return function(...args) {
try {
fn(args);
}
catch(e) {
console.error(`React Devtools encountered an error`);
console.error(e);
}
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty line at EOF.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure probably we need to add prettier, husky

3 changes: 3 additions & 0 deletions src/debug/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { initDevTools } from './devtool';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will also need to add this file on the dev build right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think it should be opt-int by the user if the user adds

import '../src/debug';

they will get support for React dev tool. do you think that there is any other better way of doing this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On rollup we can add this on dev bundle. and exclude it otherwise.


initDevTools();
Copy link
Collaborator

@s-yadav s-yadav Nov 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty line at EOF.