Last active
August 29, 2015 14:10
-
-
Save fudini/ff7882ccd8a51860af31 to your computer and use it in GitHub Desktop.
DataStore with Rx and Ramda
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
var initialData = [] | |
// These can be converted from other events | |
var add_ = new Rx.Subject() | |
var remove_ = new Rx.Subject() | |
var addF_ = add_.map(R.unary(R.curry(R.union))) | |
var removeF_ = remove_.map(R.unary(R.flip(R.difference))) | |
var update = (data, updateF) => updateF(data) | |
var data_ = addF_.merge(removeF_).scan(initialData, update).shareValue(initialData) | |
data_.subscribe(data => console.log(data)) | |
add_.onNext([1,2,3,4,5]) | |
// [1,2,3,4,5] | |
remove_.onNext([3,4,5]) | |
// [1,2] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment