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 CommentBox = React.createClass({ | |
| // getInitialState is called right when the component is initialized | |
| // its return value is set as the component's state | |
| getInitialState: function() { | |
| return {data: []}; | |
| }, | |
| // componentDidMount is called right when the DOM element is first mounted | |
| // it is not called again every time the component re-renders | 
  
    
      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 CommentForm = React.createClass({ | |
| getInitialState: function() { | |
| return {author: '', text: ''}; | |
| }, | |
| handleAuthorChange: function(e) { | |
| this.setState({author: e.target.value}); | |
| }, | |
| handleTextChange: function(e) { | 
  
    
      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 CommentBox = React.createClass({ | |
| loadCommentsFromServer: function() { | |
| ... | |
| }, | |
| handleCommentSubmit: function(comment) { | |
| // this callback POSTs the comment to the server | |
| $.ajax({ | |
| url: this.props.url, | |
| dataType: 'json', | |
| type: 'POST', | 
  
    
      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 content = <Container>{window.isLoggedIn ? <Nav /> : <Login />}</Container>; | |
| // pretty cool, eh? | 
  
    
      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 smallArray = [2,3,4] | |
| var bigArray = [1, ...smallArray, 5, 6, 7] // [1, 2, 3, 4, 5, 6, 7] | |
| // You can use it in function arguments | |
| var foo = function(a,b,c){ return a+b+c; } | |
| var args = [1,2,3] | |
| foo(...args) | |
| // like Ruby's splat, no? | 
  
    
      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 props = {}; | |
| props.foo = x; | |
| props.bar = y; | |
| var component = <Component {...props} baz={z}/>; | 
  
    
      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
    
  
  
    
  | { | |
| type: "ADD_TODO", | |
| text: "Write an article comparing 'Sexy and the City' with 'War and Peace'" | |
| } | |
| { | |
| type: "COMPLETE_TODO", | |
| index: 5 // refers to the index in the array which this todo presumably lives in | |
| } | 
  
    
      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
    
  
  
    
  | export function addTodo(text){ | |
| return { | |
| type: "ADD_TODO", | |
| text: text | |
| } | |
| } | |
| export function completeTodo(index){ | |
| return {type: "COMPLETE_TODO", index} | |
| } | 
  
    
      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
    
  
  
    
  | // example of a store for a todo app | |
| { | |
| visibilityFilter: "SHOW_ALL", | |
| todos: [ | |
| {text: "Give the monkey a haircut", completed: false}, | |
| {text: "Buy tuxedo for pet snake", completed: true}, | |
| {text: "Listen to Captain Beefheart's 'Troutmask Replica'", completed: false} | |
| ] | |
| } | 
  
    
      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
    
  
  
    
  | // an initial state | |
| // `const` means the variable cannot be reassigned, it does not | |
| // `const` DOES NOT mean the value it points to is immutable | |
| const initialState = { | |
| visbilityFilter: "SHOW ALL", | |
| todos: [] | |
| } | |
| // The naming convention is we call the reducer the same name as whatever it is updating. | |
| // In this case, it is a reducer that updates the todo-app, so we just call it `todoApp`. |