This file contains 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( | |
<Provider store={store}> | |
<Counter /> | |
</Provider> | |
, document.getElementById('root')); |
This file contains 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 mapStateToProps = (state) => { | |
return {counter: state.counter}; | |
} | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
onIncrement: () => dispatch({type: 'INCREMENT'}), | |
onDecrement: () => dispatch({type: 'DECREMENT'}) | |
} | |
} | |
Counter = connect(mapStateToProps, mapDispatchToProps)(Counter); |
This file contains 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 store = createStore(reducer, {counter: 0},window.devToolsExtension ? window.devToolsExtension() : undefined); |
This file contains 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
let Counter = ({counter, onIncrement, onDecrement}) => | |
(<div> | |
<div>{counter}</div> | |
<button onClick={onDecrement}>-</button> | |
<button onClick={onIncrement}>+</button> | |
</div>); |
This file contains 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 reducer = (state = {counter: 0}, action) => { | |
switch (action.type) { | |
case 'INCREMENT': | |
return {...state, counter: state.counter+1}; | |
case 'DECREMENT': | |
return {...state, counter: state.counter-1}; | |
default: | |
return state; | |
} | |
}; |
This file contains 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 { render } from 'react-dom'; | |
import { createStore } from 'redux'; | |
import { connect, Provider } from 'react-redux'; | |
const reducer = (state = {counter: 0}, action) => { | |
switch (action.type) { | |
case 'INCREMENT': | |
return {...state, counter: state.counter+1}; | |
case 'DECREMENT': |
This file contains 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 pureFunction(a) { | |
return a * 2; | |
} | |
var c = 6; | |
function impureFunction(a) { | |
return c * a; | |
} |
This file contains 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
scala> (-1000.0 to 1000.0 by 0.1).forall(x => df(x) == 8 * x + 6) | |
res0: Boolean = true |
This file contains 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
f(x) = 4 * Math.pow(x, 2) + 6 * x - 5 |
This file contains 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
scala> val df = Scalac.derivative(x => 2*(2 * Math.pow(x, 2) + 3 * x) + (-5)) | |
df: Double => Double = <function1> |