Skip to content

Commit 4443d15

Browse files
[added] JSDoc
Summary: Closes #13 Reviewers: O3 Material JavaScript platform reviewers, #material_motion, O2 Material Motion, markwei Reviewed By: #material_motion, O2 Material Motion, markwei Tags: #material_motion Differential Revision: http://codereview.cc/D2217
1 parent 38db6b9 commit 4443d15

7 files changed

Lines changed: 192 additions & 0 deletions

dist/IndefiniteObservable.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
import { Connect, Observable, ObserverOrNext, Subscription } from './types';
2+
/**
3+
* Observable is a standard interface that's useful for modeling multiple,
4+
* asynchronous events.
5+
*
6+
* IndefiniteObservable is a minimalist implementation of a subset of the TC39
7+
* Observable proposal. It is indefinite because it will never call `complete`
8+
* or `error` on the provided observer.
9+
*/
210
export default class IndefiniteObservable<T> implements Observable<T> {
311
_connect: Connect<T>;
12+
/**
13+
* The provided function should receive an observer and connect that
14+
* observer's `next` method to an event source (for instance,
15+
* `element.addEventListener('click', observer.next)`).
16+
*
17+
* It must return a function that will disconnect the observer from the event
18+
* source.
19+
*/
420
constructor(connect: Connect<T>);
21+
/**
22+
* `subscribe` uses the function supplied to the constructor to connect an
23+
* observer to an event source. Each observer is connected independently:
24+
* each call to `subscribe` calls `connect` with the new observer.
25+
*
26+
* To disconnect the observer from the event source, call `unsubscribe` on the
27+
* returned subscription.
28+
*
29+
* Note: `subscribe` accepts either a function or an object with a
30+
* next method.
31+
*/
532
subscribe(observerOrNext: ObserverOrNext<T>): Subscription;
633
}

dist/IndefiniteObservable.js

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/IndefiniteSubject.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
import { Observable, Observer, ObserverOrNext, Subscription } from './types';
2+
/**
3+
* An IndefiniteSubject is both an Observer and an Observable. Whenever it
4+
* receives a value on `next`, it forwards that value to any subscribed
5+
* observers.
6+
*
7+
* IndefiniteSubject is a multicast Observable; it remembers the most recent
8+
* value dispatched and passes it to any new subscriber.
9+
*/
210
export default class IndefiniteSubject<T> implements Observable<T>, Observer<T> {
311
_observers: Set<Observer<T>>;
412
_lastValue: T;
513
_hasStarted: boolean;
14+
/**
15+
* Passes the supplied value to any currently-subscribed observers. If an
16+
* observer `subscribe`s before `next` is called again, it will immediately
17+
* receive `value`.
18+
*/
619
next(value: T): void;
20+
/**
21+
* `subscribe` accepts either a function or an object with a next method.
22+
* `subject.next` will forward any value it receives to the function or method
23+
* provided here.
24+
*
25+
* Call the returned `unsubscribe` method to stop receiving values on this
26+
* particular observer.
27+
*/
728
subscribe(observerOrNext: ObserverOrNext<T>): Subscription;
829
}

dist/IndefiniteSubject.js

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/indefinite-observable.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,37 @@ var $observable = (
7474
}
7575
)();
7676

77+
/**
78+
* Observable is a standard interface that's useful for modeling multiple,
79+
* asynchronous events.
80+
*
81+
* IndefiniteObservable is a minimalist implementation of a subset of the TC39
82+
* Observable proposal. It is indefinite because it will never call `complete`
83+
* or `error` on the provided observer.
84+
*/
7785
class IndefiniteObservable {
86+
/**
87+
* The provided function should receive an observer and connect that
88+
* observer's `next` method to an event source (for instance,
89+
* `element.addEventListener('click', observer.next)`).
90+
*
91+
* It must return a function that will disconnect the observer from the event
92+
* source.
93+
*/
7894
constructor(connect) {
7995
this._connect = connect;
8096
}
97+
/**
98+
* `subscribe` uses the function supplied to the constructor to connect an
99+
* observer to an event source. Each observer is connected independently:
100+
* each call to `subscribe` calls `connect` with the new observer.
101+
*
102+
* To disconnect the observer from the event source, call `unsubscribe` on the
103+
* returned subscription.
104+
*
105+
* Note: `subscribe` accepts either a function or an object with a
106+
* next method.
107+
*/
81108
subscribe(observerOrNext) {
82109
const observer = wrapWithObserver(observerOrNext);
83110
const disconnect = this._connect(observer);
@@ -101,16 +128,37 @@ class IndefiniteObservable {
101128
}
102129
}
103130

131+
/**
132+
* An IndefiniteSubject is both an Observer and an Observable. Whenever it
133+
* receives a value on `next`, it forwards that value to any subscribed
134+
* observers.
135+
*
136+
* IndefiniteSubject is a multicast Observable; it remembers the most recent
137+
* value dispatched and passes it to any new subscriber.
138+
*/
104139
class IndefiniteSubject {
105140
constructor() {
106141
this._observers = new Set();
107142
this._hasStarted = false;
108143
}
144+
/**
145+
* Passes the supplied value to any currently-subscribed observers. If an
146+
* observer `subscribe`s before `next` is called again, it will immediately
147+
* receive `value`.
148+
*/
109149
next(value) {
110150
this._hasStarted = true;
111151
this._lastValue = value;
112152
this._observers.forEach((observer) => observer.next(value));
113153
}
154+
/**
155+
* `subscribe` accepts either a function or an object with a next method.
156+
* `subject.next` will forward any value it receives to the function or method
157+
* provided here.
158+
*
159+
* Call the returned `unsubscribe` method to stop receiving values on this
160+
* particular observer.
161+
*/
114162
subscribe(observerOrNext) {
115163
const observer = wrapWithObserver(observerOrNext);
116164
this._observers.add(observer);

src/IndefiniteObservable.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,40 @@ import {
2525
Subscription,
2626
} from './types';
2727

28+
/**
29+
* Observable is a standard interface that's useful for modeling multiple,
30+
* asynchronous events.
31+
*
32+
* IndefiniteObservable is a minimalist implementation of a subset of the TC39
33+
* Observable proposal. It is indefinite because it will never call `complete`
34+
* or `error` on the provided observer.
35+
*/
2836
export default class IndefiniteObservable<T> implements Observable<T> {
2937
_connect: Connect<T>;
3038

39+
/**
40+
* The provided function should receive an observer and connect that
41+
* observer's `next` method to an event source (for instance,
42+
* `element.addEventListener('click', observer.next)`).
43+
*
44+
* It must return a function that will disconnect the observer from the event
45+
* source.
46+
*/
3147
constructor(connect: Connect<T>) {
3248
this._connect = connect;
3349
}
3450

51+
/**
52+
* `subscribe` uses the function supplied to the constructor to connect an
53+
* observer to an event source. Each observer is connected independently:
54+
* each call to `subscribe` calls `connect` with the new observer.
55+
*
56+
* To disconnect the observer from the event source, call `unsubscribe` on the
57+
* returned subscription.
58+
*
59+
* Note: `subscribe` accepts either a function or an object with a
60+
* next method.
61+
*/
3562
subscribe(observerOrNext: ObserverOrNext<T>): Subscription {
3663
// For simplicity's sake, `subscribe` accepts `next` either as either an
3764
// anonymous function or wrapped in an object (the observer). Since

src/IndefiniteSubject.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,26 @@ import {
2525
Subscription,
2626
} from './types';
2727

28+
/**
29+
* An IndefiniteSubject is both an Observer and an Observable. Whenever it
30+
* receives a value on `next`, it forwards that value to any subscribed
31+
* observers.
32+
*
33+
* IndefiniteSubject is a multicast Observable; it remembers the most recent
34+
* value dispatched and passes it to any new subscriber.
35+
*/
2836
export default class IndefiniteSubject<T> implements Observable<T>, Observer<T> {
2937
// Keep track of all the observers who have subscribed, so we can notify them
3038
// when we get new values. Note: JavaScript's Set collection is ordered.
3139
_observers: Set<Observer<T>> = new Set();
3240
_lastValue: T;
3341
_hasStarted: boolean = false;
3442

43+
/**
44+
* Passes the supplied value to any currently-subscribed observers. If an
45+
* observer `subscribe`s before `next` is called again, it will immediately
46+
* receive `value`.
47+
*/
3548
next(value: T) {
3649
this._hasStarted = true;
3750
this._lastValue = value;
@@ -44,6 +57,14 @@ export default class IndefiniteSubject<T> implements Observable<T>, Observer<T>
4457
);
4558
}
4659

60+
/**
61+
* `subscribe` accepts either a function or an object with a next method.
62+
* `subject.next` will forward any value it receives to the function or method
63+
* provided here.
64+
*
65+
* Call the returned `unsubscribe` method to stop receiving values on this
66+
* particular observer.
67+
*/
4768
subscribe(observerOrNext: ObserverOrNext<T>): Subscription {
4869
const observer = wrapWithObserver<T>(observerOrNext);
4970

0 commit comments

Comments
 (0)