Skip to content

Commit 7ebff77

Browse files
lbogdanCompuIves
authored andcommitted
DevTools / console enhancements (codesandbox#267)
* Renamed cryptic 'massage' to less cryptic 'transform'. :-) * Console: changed word break, break-word is better. * Console: also catch console.clear(). * DevTools: remember height.
1 parent 74a34c4 commit 7ebff77

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

src/app/components/sandbox/Preview/DevTools/Console/Message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const Container = styled.div`
8080
border-bottom: 1px solid rgba(0, 0, 0, 0.3);
8181
font-size: 13px;
8282
line-height: 16px;
83-
word-break: break-all;
83+
word-break: break-word;
8484
${props => getTypeStyles(props.logType)};
8585
`;
8686

src/app/components/sandbox/Preview/DevTools/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import Tooltip from 'app/components/Tooltip';
77

88
import MinimizeIcon from 'react-icons/lib/fa/angle-up';
99

10+
import store from 'store/dist/store.modern';
11+
1012
import Unread from './Unread';
1113

1214
import console from './Console';
@@ -230,7 +232,11 @@ export default class DevTools extends React.PureComponent<Props, State> {
230232
// happen when pointer events are disabled and in turn disables scroll.
231233
// It's hacky, but it's to fix a bug in the browser.
232234
setTimeout(() => {
233-
this.setState({ height: this.state.height + 1 });
235+
const height = this.state.height + 1;
236+
this.setState({ height });
237+
if (height > 64) {
238+
store.set('devtools.height', height);
239+
}
234240
}, 50);
235241
}
236242
}
@@ -272,7 +278,7 @@ export default class DevTools extends React.PureComponent<Props, State> {
272278
this.setHidden(false);
273279
const heightObject = { height: this.state.height };
274280
TweenMax.to(heightObject, 0.3, {
275-
height: 300,
281+
height: store.get('devtools.height') || 300,
276282
onUpdate: () => {
277283
this.setState(heightObject);
278284
},

src/sandbox/console/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { dispatch } from 'codesandbox-api';
22

3-
import massageJSON from './massage-json';
3+
import transformJSON from './transform-json';
44

55
function replaceConsoleMethod(method) {
66
const oldMethod = console[method];
77
console[method] = (...args) => {
88
try {
9-
if (args.length > 0) {
9+
if (method === 'clear') {
10+
dispatch({ type: 'clear-console' });
11+
} else if (args.length > 0) {
1012
dispatch({
1113
type: 'console',
1214
method,
13-
args: massageJSON(args),
15+
args: transformJSON(args),
1416
});
1517
}
1618
} catch (e) {

src/sandbox/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import host from './utils/host';
1010
import setupHistoryListeners from './url-listeners';
1111
import compile from './compile';
1212
import setupConsole from './console';
13-
import massageJSON from './console/massage-json';
13+
import transformJSON from './console/transform-json';
1414

1515
function getId() {
1616
if (process.env.LOCAL_SERVER) {
@@ -49,7 +49,7 @@ requirePolyfills().then(() => {
4949
dispatch({
5050
type: 'eval-result',
5151
error,
52-
result: massageJSON(result),
52+
result: transformJSON(result),
5353
});
5454
} catch (e) {
5555
console.error(e);

0 commit comments

Comments
 (0)