Skip to content

Instantly share code, notes, and snippets.

@fudini
Last active August 29, 2015 14:10
Show Gist options
  • Save fudini/ff7882ccd8a51860af31 to your computer and use it in GitHub Desktop.
Save fudini/ff7882ccd8a51860af31 to your computer and use it in GitHub Desktop.
DataStore with Rx and Ramda
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