Last active
May 29, 2018 13:23
-
-
Save fourscience/70ad579954cd33c9be7ee767f4d9c604 to your computer and use it in GitHub Desktop.
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
function NOOP(){} | |
function Observable(subscriber = NOOP) { | |
function create(operand = v => v) { | |
return new Observable(observer => this.subscribe(v => { | |
let b = operand(v); | |
this.value = typeof b !== 'boolean' ? b : b && v; | |
this.value && observer.next(this.value); | |
}) | |
); | |
} | |
function subscribe(next, error = NOOP, complete = NOOP) { | |
let unsubscribe; | |
this.observer = { | |
next: v => { this.value = v; next(v) }, | |
error, | |
complete: () => { complete(); unsubscribe() }, | |
}; | |
unsubscribe = subscriber(this.observer) | |
return { unsubscribe } | |
} | |
return { | |
create, | |
subscribe, | |
map: create, | |
value: null, | |
filter: create, | |
observer: null, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment