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
| var VideoWrapper = React.createClass({ | |
| render: function() { | |
| return ( | |
| <Video ref="video" src="path/to/my/video.mp4" /> | |
| ); | |
| }, | |
| componentDidMount: function() { | |
| // I will show the rendered Video instance | |
| // in the console | |
| console.log( this.refs.video ); |
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
| var VideoWrapper = React.createClass({ | |
| getInitialState: function(){ | |
| return {play: false, time: '0:00:000'}; | |
| }, | |
| render: function() { | |
| return ( | |
| <Video src="path/to/my/video.mp4" | |
| play={ this.state.play } | |
| onButtonClick={ () => this.setState({play: !this.state.play}) } | |
| time={ this.state.time } /> |
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
| <Video src="path/to/my/video.mp4" | |
| play={ this.state.play } | |
| onButtonClick={ () => this.setState({play: !this.state.play}) } | |
| time="1:00:000" /> |
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
| var VideoWrapper = React.createClass({ | |
| getInitialState: function(){ | |
| return {play: false}; | |
| }, | |
| render: function() { | |
| return ( | |
| <Video src="path/to/my/video.mp4" | |
| play={ this.state.play } | |
| onButtonClick={ () => this.setState({play: !this.state.play}) } /> | |
| ); |
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
| State.on('todo:update', function( todo, text ){ | |
| // Setting the status to updating we can show | |
| // a deleting message in the component. | |
| var updated = todo.pivot().ui.set({ status: 'updating' }); | |
| // Emulate a server call | |
| setTimeout( function(){ | |
| var todo = State.get().todos.find( updated ); | |
| // We need to pivot in the node to modify multiple children. |
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
| var TodoList = React.createClass({ | |
| ... | |
| shouldComponentUpdate: function( nextProps ){ | |
| return nextProps.todos != this.props.todos; | |
| } | |
| ... | |
| }); |
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
| // Our input is something like | |
| var TodoInput = React.createElement({ | |
| render: function(){ | |
| return <input value={ this.props.state.todoInput } onChange={ this.updateInput } /> | |
| }, | |
| updateInput: function(){ | |
| // We don't need to create a reaction for this, | |
| // This is not a problem because the whole state will be | |
| // updated and the whole app will be notified of this change | |
| this.props.state.set({ todoInput: e.target.value }).now() |
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
| /* STANDARD FLUX */ | |
| // Using flux you need to register the action in the dispatcher | |
| AppDispatcher.register(function(payload) { | |
| var action = payload.action; | |
| var text; | |
| switch(action.actionType) { | |
| case 'updateTodo': | |
| text = action.text.trim(); | |
| if (text !== '') { |
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
| /* FREEZER */ | |
| // Create a reaction | |
| freezer.on('todo:update', function( todo, text ){ | |
| todo.model.set({title: text}); | |
| }); | |
| // Trigger the event from your component | |
| var TodoList = React.createComponent({ | |
| ... | |
| updateTodo: function( todo, text ){ |
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
| // Creaing a todo item | |
| // using a standard flux dispatcher | |
| dispatch({actionType: 'createTodo', title: 'Do this.'}); | |
| // using freezer | |
| freezer.trigger('todo:create', 'Do this.'); |