Last active
October 13, 2017 22:22
-
-
Save gbrennon/71aa1950c88a1ed541213ef7e55d8ba1 to your computer and use it in GitHub Desktop.
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
| class MeuComponent extends React.Component { | |
| render() { | |
| return <h1>{{this.props.text}}</h1>; | |
| } | |
| } | |
| let mountNode = document.getElementById('root'); | |
| ReactDOM.render( | |
| <MeuComponent text='Título />, | |
| mountNode | |
| ); | |
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 { createStore } from 'redux' | |
| /** | |
| * counter é um reducer, ou seja, uma função pura que recebe como argumentos um estado e uma ação. | |
| * O reducer tem como responsabilidade descrever como uma ação modifica o estado no próximo estado. | |
| * This is a reducer, a pure function with (state, action) => state signature. | |
| * | |
| **/ | |
| function counter(state = 0, action) { | |
| switch (action.type) { | |
| case 'INCREMENT': | |
| return state + 1 | |
| case 'DECREMENT': | |
| return state - 1 | |
| default: | |
| return state | |
| } | |
| } | |
| // Registro da função counter como store. | |
| let store = createStore(counter) | |
| /* Através do método subscribe eventos podem ser registrados para executar no momento | |
| * que o estado muda. | |
| */ | |
| store.subscribe(() => | |
| console.log(store.getState()) | |
| ) | |
| /* Após registrar a função como store e anexar um evento a store, | |
| * a aplicaço deve realizar dispatch para desencadear mudanças na árvore de estados. | |
| */ | |
| store.dispatch({ type: 'INCREMENT' }) | |
| // 1 | |
| store.dispatch({ type: 'INCREMENT' }) | |
| // 2 | |
| store.dispatch({ type: 'DECREMENT' }) | |
| // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment