This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <label> Name: | |
| <input type="text" | |
| value={ state.name } | |
| onChange={ e => this.setState({ name : e.target.value }) }/> | |
| </label> | |
| <label> Email: | |
| <input type="text" | |
| value={ state.email } | |
| onChange={ e => this.setState({ email : e.target.value }) }/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Input = ({ ???, ...props }) => ( | |
| <input {...props} | |
| onChange={ ? } | |
| value={ ? } | |
| /> | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function linkState( component, attr ){ | |
| return { | |
| value : component.state[ attr ], | |
| set( x ){ | |
| component.setState({ [ attr ] : x }); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Input type="text" link={ linkState( this, 'name' ) } /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Input = ({ link, ...props }) => ( | |
| <input {...props} | |
| onChange={ e => link.set( e.target.value ) } | |
| value={ link.value } | |
| /> | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| render(){ | |
| const linked = this.linkAll(); | |
| return ( | |
| <form onSubmit={ this.onSubmit }> | |
| <label> Name: | |
| <input type="text" { ...linked.name.props } /> | |
| </label> | |
| <label> Email: | |
| <input type="text" { ...linked.email.props } /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @define class UserForm extends React.Component { | |
| static state = { | |
| name : '', | |
| email : '', | |
| isActive : true | |
| } | |
| onSubmit = () => { /* TBD */ }; | |
| onCancel = () => { /* TBD */ }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { define, Record } from 'type-r'; | |
| @define | |
| export class Box extends Record { | |
| static attributes = { | |
| x : Number, | |
| y : Number, | |
| location : String | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const AfterRenderMixin = { | |
| componentDidMount : callAfterRenderHooks, | |
| componentDidUpdate : callAfterRenderHooks, | |
| afterRender( hook ){ | |
| const { _callAfterRender } = this; | |
| this._callafterRender = _callAfterRender ? () => { | |
| _callAfterRender(); | |
| hook(); | |
| } : hook; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { useLink } from 'valuelink' | |
| function Example() { | |
| const counter = useLink(0); | |
| return ( | |
| <div> | |
| <p>You clicked {counter.value} times</p> | |
| <button onClick={counter.action( x => x + 1 )}> |