Last active
July 13, 2019 14:09
-
-
Save iazel/9ed4d330ee05695a0b07106c4daf92af to your computer and use it in GitHub Desktop.
Composable UI / TodoStore / Visibility Filter
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
class TodoStore { | |
private readonly visibilityFilter: $Predicate$<Todo> & Destroyable | |
constructor() { | |
this.visibilityFilter = map(this.visibility, vis2pred) | |
} | |
getVisibilityFilter(): $Preidcate$<Todo> { | |
return this.visibilityFilter | |
} | |
dispose() { | |
this.visibilityFilter.destroy() | |
} | |
} | |
function vis2pred(v: Visibility): Predicate$<Todo> { | |
switch (v) { | |
case Visibility.ALL: | |
const $true = new StreamBox(true) | |
return () => $true | |
case Visibility.DONE: | |
return (todo) => clone(todo.done) | |
case Visibility.TODO: | |
return (todo) => map(todo.done, (b) => !b) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment