Last active
August 29, 2015 14:16
-
-
Save Willmo36/011788a1d0eef2467f26 to your computer and use it in GitHub Desktop.
Kefir flux store example
This file contains 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
let Kefir = require("kefir"); | |
function BlogStore(actions, initialState) { | |
//map the action stream to a stream which returns a function which modifies the state. | |
let createPost = actions.Post.create.map((newPost) => { | |
//the scan method will call this with the current vaule (allPosts) | |
return (allPosts) => { | |
allPosts.push(newPost); | |
return allPosts; | |
} | |
}); | |
//alt way of writing. | |
//let createPost = actions.Posts.create.map((newPost) => (allPosts) => { | |
// allPosts.push(newPost); | |
// return allPosts; | |
//}); | |
let posts = Kefir | |
.merge([createPost]) | |
.scan((allPosts, mod) => mod(allPosts), initialState) | |
.toProperty(); | |
return { | |
posts | |
} | |
} | |
module.exports = BlogStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment