##// END OF EJS Templates
Added tag v1.9.0-rc4 for changeset 515d1b83ebdf
Added tag v1.9.0-rc4 for changeset 515d1b83ebdf

File last commit:

r136:435ce00ba245 v1.9.0-rc2 default
r141:4a811097b6fc default
Show More
subject.ts
50 lines | 1.6 KiB | video/mp2t | TypeScriptLexer
cin
added store::get method to wrap up dojo/store/get
r136 import { Observable, Sink, Subscribable, observe } from "../observable";
cin
added 'buffer' and 'subject' observable operators
r133
const noop = () => { };
/** Joins multiple subscribers to the single one. The resulting subscriber
* will be created when the first client subscribes and will be released
* with the the last client unsubscribed.
*
* Use this wrapper to prevent spawning multiple producers.
*
* @param source The source observable
* @returns The wrapped producer
*/
cin
added store::get method to wrap up dojo/store/get
r136 export const subject = <T>(source: Subscribable<T>): Observable<T> => {
cin
added 'buffer' and 'subject' observable operators
r133 let subscribers: Sink<T>[] = [];
let subscription = { unsubscribe: noop };
// cleanup method to release resources held by this subscription
const cleanup = (cb: (item: Sink<T>) => void) => {
const _subscribers = subscribers;
subscribers = [];
_subscribers.forEach(cb);
subscription.unsubscribe();
};
const sink: Sink<T> = {
isClosed: () => false,
complete: () => cleanup(s => s.complete()),
error: e => cleanup(s => s.error(e)),
next: v => subscribers.forEach(s => s.next(v))
};
cin
added store::get method to wrap up dojo/store/get
r136 return observe(client => {
cin
added 'buffer' and 'subject' observable operators
r133 const _subscribers = subscribers;
subscribers.push(client);
if (subscribers.length === 1)
subscription = source.subscribe(sink);
return () => {
if (_subscribers === subscribers) {
const pos = subscribers.indexOf(client);
if (pos >= 0)
subscribers.splice(pos, 1);
if (!subscribers.length)
subscription.unsubscribe();
}
};
cin
added store::get method to wrap up dojo/store/get
r136 });
cin
added 'buffer' and 'subject' observable operators
r133 };