Last active
May 29, 2019 22:21
-
-
Save bradfordlemley/c0a7a96bf15da06914e8098ddbdc6973 to your computer and use it in GitHub Desktop.
Advanced composed state
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
import { mapState } from '@stated-library/core'; | |
const todoLib = createTodoLib(); | |
const counterLib = createCounterLib(); | |
const visLib = createVisibilityLib(); | |
const visibleTodos$ = mapState( | |
[todoLib.state$, visLib.state$], | |
([todoLibState, visLibState]) => { | |
switch (visLibState.filter) { | |
case "active": | |
return todoLibState.activeTodos; | |
case "completed": | |
return todoLibState.completedTodos; | |
default: | |
return todoLibState.todos; | |
} | |
} | |
); | |
const appState$ = mapState( | |
[todoLib.state$, visibleTodos$], | |
([todoLibState, visibleTodos]) => ({ | |
visibleTodos, | |
allTodos: todoLibState.todos, | |
addTodo: todoLib.addTodo, | |
}); | |
); | |
const anotherViewState$ = mapState( | |
[counterLib.state$, visibleTodos$], | |
([counterLibState, visibleTodos]) => ({ | |
visibleTodos, | |
counter: counterLibState, | |
}); | |
); | |
export { anotherViewState$, appState$, todoLib, visLib, visibleTodos$ }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment