Created
April 2, 2016 08:32
-
-
Save anonymous/b82c2480277f108c01c70627592c2a29 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/jebaxa
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.1.0/rx.all.compat.js"></script> | |
</head> | |
<body> | |
<h2>Counter: <span id="counter"></span></h2> | |
<button onclick="increment$.onNext()">Increment</button> | |
<button onclick="decrement$.onNext()">Decrement</button> | |
<script id="jsbin-javascript"> | |
"use strict"; | |
function projectIncrement() { | |
return function (state) { | |
return Object.assign({}, state, { | |
count: state.count + 1 | |
}); | |
}; | |
} | |
function projectDecrement() { | |
return function (state) { | |
return Object.assign({}, state, { | |
count: state.count - 1 | |
}); | |
}; | |
} | |
var initState = { count: 0 }; | |
var increment$ = new Rx.Subject(); | |
var decrement$ = new Rx.Subject(); | |
var state$ = Rx.Observable.merge(increment$.map(projectIncrement), decrement$.map(projectDecrement)).startWith(initState).scan(function (state, project) { | |
console.log('inc1', state, project); | |
return project(state); | |
}); | |
state$.subscribe(function (state) { | |
var counter = document.getElementById("counter"); | |
counter.innerHTML = state.count; | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function projectIncrement() { | |
return function(state) { | |
return Object.assign({}, state, { | |
count: state.count + 1 | |
}); | |
}; | |
} | |
function projectDecrement() { | |
return function (state) { | |
return Object.assign({}, state, { | |
count: state.count - 1 | |
}); | |
}; | |
} | |
const initState = {count: 0}; | |
const increment$ = new Rx.Subject(); | |
const decrement$ = new Rx.Subject(); | |
const state$ = Rx.Observable | |
.merge( | |
increment$.map(projectIncrement), | |
decrement$.map(projectDecrement) | |
) | |
.startWith(initState) | |
.scan(function (state, project) { | |
console.log('inc1', state, project); | |
return project(state); | |
}); | |
state$.subscribe((state) => { | |
const counter = document.getElementById("counter"); | |
counter.innerHTML = state.count; | |
});</script></body> | |
</html> |
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"; | |
function projectIncrement() { | |
return function (state) { | |
return Object.assign({}, state, { | |
count: state.count + 1 | |
}); | |
}; | |
} | |
function projectDecrement() { | |
return function (state) { | |
return Object.assign({}, state, { | |
count: state.count - 1 | |
}); | |
}; | |
} | |
var initState = { count: 0 }; | |
var increment$ = new Rx.Subject(); | |
var decrement$ = new Rx.Subject(); | |
var state$ = Rx.Observable.merge(increment$.map(projectIncrement), decrement$.map(projectDecrement)).startWith(initState).scan(function (state, project) { | |
console.log('inc1', state, project); | |
return project(state); | |
}); | |
state$.subscribe(function (state) { | |
var counter = document.getElementById("counter"); | |
counter.innerHTML = state.count; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment