| 
									
										
										
										
											2021-08-08 02:51:39 +03:00
										 |  |  | <link rel=stylesheet href='./style.css'> | 
					
						
							|  |  |  | <script src="./react_17.0.2.js"></script> | 
					
						
							|  |  |  | <script src="./react-dom_17.0.2.js"></script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <div id=root></div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  | const e = React.createElement; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function AppHeader(props) { | 
					
						
							|  |  |  |   return e(React.Fragment, null, | 
					
						
							|  |  |  |     e('h1', null, `reactjs@${React.version}`), | 
					
						
							|  |  |  |     e('h3', null, `Reading List: ${props.bookCount}`), | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NewBook extends React.Component { | 
					
						
							|  |  |  |   constructor(props) { | 
					
						
							|  |  |  |     super(props); | 
					
						
							|  |  |  |     this.state = ''; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onInput(event) { | 
					
						
							|  |  |  |     this.state = event.target.value; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   render() { | 
					
						
							|  |  |  |     return e(React.Fragment, null, | 
					
						
							|  |  |  |       e('input', {onInput: this.onInput.bind(this)}, null), | 
					
						
							|  |  |  |       e('button', { | 
					
						
							|  |  |  |         onClick: () => this.props.onNewBook(this.state), | 
					
						
							|  |  |  |       }, `new book`), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  | function ColorButton (props) { | 
					
						
							|  |  |  |   return e('button', {className: props.color, disabled: !props.enabled}, 'button ' + props.nested.index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function ButtonGrid() { | 
					
						
							|  |  |  |   const buttons = []; | 
					
						
							|  |  |  |   for (let i = 0; i < 9; ++i) { | 
					
						
							|  |  |  |     buttons.push(e(ColorButton, { | 
					
						
							|  |  |  |       color: ['red', 'green', 'blue'][i % 3], | 
					
						
							|  |  |  |       enabled: i % 2 === 0, | 
					
						
							|  |  |  |       nested: { | 
					
						
							|  |  |  |         index: i, | 
					
						
							|  |  |  |         value: i + 0.1, | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, null)); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   return e(React.Fragment, null, ...buttons); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-08 02:51:39 +03:00
										 |  |  | class BookItem extends React.Component { | 
					
						
							|  |  |  |   render() { | 
					
						
							|  |  |  |     return e('div', null, this.props.name); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BookList extends React.Component { | 
					
						
							|  |  |  |   render() { | 
					
						
							|  |  |  |     return e('ol', null, this.props.books.map(book => e('li', {key: book.name}, e(BookItem, { name: book.name })))); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class App extends React.Component { | 
					
						
							|  |  |  |   constructor(props) { | 
					
						
							|  |  |  |     super(props); | 
					
						
							| 
									
										
										
										
											2021-08-26 13:07:33 +03:00
										 |  |  |     this.mountPoint = React.createRef(); | 
					
						
							| 
									
										
										
										
											2021-08-08 02:51:39 +03:00
										 |  |  |     this.state = { | 
					
						
							|  |  |  |       books: [ | 
					
						
							|  |  |  |         {name: 'Pride and Prejudice' }, | 
					
						
							|  |  |  |         {name: 'To Kill a Mockingbird' }, | 
					
						
							|  |  |  |         {name: 'The Great Gatsby' }, | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   render() { | 
					
						
							|  |  |  |     return e(React.Fragment, null, | 
					
						
							|  |  |  |       e(AppHeader, {bookCount: this.state.books.length}, null), | 
					
						
							|  |  |  |       e(NewBook, {onNewBook: bookName => this.onNewBook(bookName)}, null), | 
					
						
							|  |  |  |       e(BookList, {books: this.state.books}, null), | 
					
						
							| 
									
										
										
										
											2021-08-11 03:10:14 +03:00
										 |  |  |       e(ButtonGrid, null, null), | 
					
						
							| 
									
										
										
										
											2021-08-26 13:07:33 +03:00
										 |  |  |       e('div', {ref: this.mountPoint}, null), | 
					
						
							| 
									
										
										
										
											2021-08-08 02:51:39 +03:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onNewBook(bookName) { | 
					
						
							|  |  |  |     this.setState({ | 
					
						
							|  |  |  |       books: [...this.state.books, {name: bookName}], | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-20 15:05:52 +03:00
										 |  |  | window.mountApp = element => ReactDOM.render(e(App, null, null), element); | 
					
						
							| 
									
										
										
										
											2021-08-26 13:07:33 +03:00
										 |  |  | window.app = window.mountApp(document.getElementById('root')); | 
					
						
							|  |  |  | window.mountNestedApp = () => window.mountApp(window.app.mountPoint.current); | 
					
						
							| 
									
										
										
										
											2021-08-08 02:51:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | </script> |