Skip to content

Instantly share code, notes, and snippets.

Avatar

Patryk Jażdżewski pjazdzewski1990

View GitHub Profile
View store.js
render(
<Provider store={store}>
<Counter />
</Provider>
, document.getElementById('root'));
View mapState.js
const mapStateToProps = (state) => {
return {counter: state.counter};
}
const mapDispatchToProps = (dispatch) => {
return {
onIncrement: () => dispatch({type: 'INCREMENT'}),
onDecrement: () => dispatch({type: 'DECREMENT'})
}
}
Counter = connect(mapStateToProps, mapDispatchToProps)(Counter);
View store.js
const store = createStore(reducer, {counter: 0},window.devToolsExtension ? window.devToolsExtension() : undefined);
View counter.js
let Counter = ({counter, onIncrement, onDecrement}) =>
(<div>
<div>{counter}</div>
<button onClick={onDecrement}>-</button>
<button onClick={onIncrement}>+</button>
</div>);
View reducer.js
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;
}
};
View index.js
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':
View pureAndImpure.js
function pureFunction(a) {
return a * 2;
}
var c = 6;
function impureFunction(a) {
return c * a;
}
View FinalTest3.scala
scala> (-1000.0 to 1000.0 by 0.1).forall(x => df(x) == 8 * x + 6)
res0: Boolean = true
View FinalTest.scala
f(x) = 4 * Math.pow(x, 2) + 6 * x - 5
View FinalTest.scala
scala> val df = Scalac.derivative(x => 2*(2 * Math.pow(x, 2) + 3 * x) + (-5))
df: Double => Double = <function1>
You can’t perform that action at this time.