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
| const calculatorReducer = guard({ add, subtract, multiply, divide }) |
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
| const calculatorReducer = guard({ | |
| add: add | |
| subtract: subtract | |
| multiply: multiply | |
| divide: divide | |
| }) |
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
| const calculatorReducer = guard({ | |
| add: (state, payload) => state + payload], | |
| subtract: (state, payload) => state - payload], | |
| multiply: (state, payload) => state * payload], | |
| divide: (state, payload) => state / payload], | |
| }) |
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
| { | |
| add: (state, payload) => state + payload], | |
| subtract: (state, payload) => state - payload], | |
| ... | |
| } |
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
| const typeHandlers = cond([ | |
| [equals("add"), (type, state, payload) => state + payload], | |
| [equals("subtract"), (type, state, payload) => state - payload], | |
| [equals("multiply"), (type, state, payload) => state * payload], | |
| [equals("divide"), (type, state, payload) => state / payload], | |
| [T, (type, state, payload) => state] | |
| ]) | |
| const calculatorReducer = (state, { type, payload }) => | |
| typeHandlers(type, state, payload) |
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
| const fn = cond([ | |
| [equals(0), always('water freezes at 0°C')], | |
| [equals(100), always('water boils at 100°C')], | |
| [T, (temp) => `nothing special happens at ${temp}°C`] | |
| ]) | |
| fn(0) //=> 'water freezes at 0°C' | |
| fn(50) //=> 'nothing special happens at 50°C' | |
| fn(100) //=> 'water boils at 100°C' |
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
| const calculatorReducer = (state, { type, payload }) { | |
| switch (type) { | |
| case 'add': | |
| return state + payload | |
| case 'subtract': | |
| return state - payload | |
| case 'multiply': | |
| return state * payload | |
| case 'divide': | |
| return state / payload |
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
| calculatorReducer "add" state payload = state + payload | |
| calculatorReducer "subtract" state payload = state - payload | |
| calculatorReducer "multiply" state payload = state * payload | |
| calculatorReducer "divide" state payload = state / payload | |
| calculatorReducer _ state _ = state | |
| -- or | |
| calculatorReducer type state payload | |
| | eq "add" = state + payload |
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
| 'use strict'; | |
| var gulp = require('gulp'), | |
| browserify = require('browserify'), | |
| source = require('vinyl-source-stream'), | |
| runSequence = require('run-sequence'), | |
| react = require('gulp-react'), | |
| cjsx = require('gulp-cjsx'); | |
| gulp.task('app', function() { |
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
| Counter = React.createClass | |
| getInitialState: -> | |
| count: 0 | |
| increment: -> | |
| @setState(count: @state.count + 1) | |
| render: -> | |
| <div> | |
| { @state.count } |