Skip to content

Commit

Permalink
Merge pull request #2 from snowak-cb/console-improvements-for-live-re…
Browse files Browse the repository at this point in the history
…sponse

Console improvements for live response
  • Loading branch information
snowak-cb authored Jul 12, 2017
2 parents 548cc92 + 2fe9ef5 commit 42c0442
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Properties you can pass to the console element
| Member | Type | Description
| ---- | ---- | ----
| log | (...messages: any)=>void | Log messages to the console. If string, print the value, otherwise, print the JSON value of the message.
| updateLastLog| (...messages: any)=>void | Replace the last message in the console. Useful for progress indicators.
| logX | (type: string, ...messages: any)=>void | Log messages of a particular type to the console. The messages will be given the class `react-console-message-{type}`.
| logTable | (tableObject: Object)=>void | Log tabular data to the console. `tableObject` has the format `{ headers: ['header 1', 'header 2'], rows: [['row 1, col 1', 'row 1, col 2'], ['row 2, col 1', 'row 2, col 2']]}`. `headers` is optional.
| return | ()=>void | Signal the current command has finished and a new prompt should be displayed.
Expand Down
Binary file modified dist/dist-min.tar.gz
Binary file not shown.
Binary file modified dist/dist-min.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/dist-min/react-console.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dist-min/react-console.min.js.map

Large diffs are not rendered by default.

Binary file modified dist/dist.tar.gz
Binary file not shown.
Binary file modified dist/dist.zip
Binary file not shown.
21 changes: 21 additions & 0 deletions dist/dist/react-console.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/dist/react-console.js.map

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions lib/react-console.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/react-console.js.map

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions src/react-console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,32 @@ export default class extends React.Component<ConsoleProps,ConsoleState> {
focus?: HTMLElement;
} = {};
// Command API
updateLastLog = (...messages: any[]) => {
let log = this.state.log;
if(!log.length){
log.push({label: '', command: '', message: [] });
}
let indexToReplace = log[this.state.log.length-1].message.length > 0 ? log[this.state.log.length-1].message.length - 1 : 0;
log[this.state.log.length-1].message[indexToReplace] = {value: messages};
this.setState({
log: log,
}, this.scrollIfBottom() );
}
log = (...messages: any[]) => {
let log = this.state.log;
if(!log.length){
log.push({label: '', command: '', message: [] });
}
log[this.state.log.length-1].message.push({value: messages});
this.setState({
log: log,
}, this.scrollIfBottom() );
}
logX = (type: string, ...messages: any[]) => {
let log = this.state.log;
if(!log.length){
log.push({label: '', command: '', message: [] });
}
log[this.state.log.length-1].message.push({type: type, value: messages});
this.setState({
log: log,
Expand Down

0 comments on commit 42c0442

Please sign in to comment.