Skip to content

Commit

Permalink
Idiomatic typescript example
Browse files Browse the repository at this point in the history
  • Loading branch information
astralarya committed Jun 1, 2016
1 parent 6252742 commit ac113c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Empty file removed dist/.mkdir
Empty file.
2 changes: 1 addition & 1 deletion example/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<div id="console"></div>
<script src="/react-console.js"></script>
<script>
ExampleConsole.init(document.getElementById("console"));
Example.init(document.getElementById("console"));
</script>
</body>
23 changes: 14 additions & 9 deletions example/example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import Console from '../src/react-console.tsx';

export function init(element: Element) {
let ReactConsole = ReactDOM.render(<Console handler={echo}/>, element) as Console;
function echo(text: string) {
window.setTimeout(function() {
ReactConsole.log(text);
window.setTimeout(function() {
ReactConsole.return();
},200);
}, 500);
class EchoConsole extends React.Component<{},{}> {
child: {
console?: Console,
} = {};
echo = (text: string) => {
this.child.console.log(text);
this.child.console.return();
}
render() {
return <Console ref={ref => this.child.console = ref} handler={this.echo}/>;
}
}

export function init(element: Element) {
ReactDOM.render(<EchoConsole/>, element);
}
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let development = Object.assign({},config, {
output: {
path: __dirname + '/example/dist',
filename: 'react-console.js',
library: "ExampleConsole",
library: "Example",
libraryTarget: "var",
},
});
Expand Down

0 comments on commit ac113c2

Please sign in to comment.