-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove internal observable imlementation
- Loading branch information
James Baxley
committed
Aug 28, 2017
1 parent
1387b59
commit abb8239
Showing
6 changed files
with
109 additions
and
130 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,11 @@ | ||
// This simplified polyfill attempts to follow the ECMAScript Observable proposal. | ||
// See https://github.com/zenparsing/es-observable | ||
|
||
import { Observable as LinkObservable } from 'apollo-link-core'; | ||
import $$observable from 'symbol-observable'; | ||
|
||
export type CleanupFunction = () => void; | ||
export type SubscriberFunction<T> = ( | ||
observer: Observer<T>, | ||
) => Subscription | CleanupFunction; | ||
|
||
function isSubscription( | ||
subscription: Function | Subscription, | ||
): subscription is Subscription { | ||
return (<Subscription>subscription).unsubscribe !== undefined; | ||
} | ||
|
||
export class Observable<T> { | ||
private subscriberFunction: SubscriberFunction<T>; | ||
|
||
constructor(subscriberFunction: SubscriberFunction<T>) { | ||
this.subscriberFunction = subscriberFunction; | ||
} | ||
|
||
// rxjs interopt | ||
export class Observable<T> extends LinkObservable<T> { | ||
public [$$observable]() { | ||
return this; | ||
} | ||
|
||
public subscribe(observer: Observer<T>): Subscription { | ||
let subscriptionOrCleanupFunction = this.subscriberFunction(observer); | ||
|
||
if (isSubscription(subscriptionOrCleanupFunction)) { | ||
return subscriptionOrCleanupFunction; | ||
} else { | ||
return { | ||
unsubscribe: subscriptionOrCleanupFunction, | ||
}; | ||
} | ||
} | ||
} | ||
|
||
export interface Observer<T> { | ||
next?: (value: T) => void; | ||
error?: (error: Error) => void; | ||
complete?: () => void; | ||
} | ||
|
||
export interface Subscription { | ||
unsubscribe: CleanupFunction; | ||
} |