Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit 5e2602d

Browse files
BehaviorSubject.getValue() typescript definitions and documentation added.
1 parent 12e211d commit 5e2602d

3 files changed

Lines changed: 57 additions & 5 deletions

File tree

doc/api/subjects/behaviorsubject.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ subject.onCompleted();
4141

4242
## `BehaviorSubject Instance Methods` ##
4343
- [`dispose`](#rxbehaviorsubjectprototypedispose)
44+
- [`getValue`] (#rxbehaviorsubjectprototypegetvalue)
4445
- [`hasObservers`](#rxbehaviorsubjectprototypehasobservers)
4546

4647
## Inherited Classes ##
@@ -50,7 +51,7 @@ subject.onCompleted();
5051
## _BehaviorSubject Constructor_ ##
5152

5253
### <a id="rxbehaviorsubjectintialvalue"></a>`Rx.BehaviorSubject(initialValue)`
53-
<a href="#rxbehaviorsubjectintialvalue">#</a> [&#x24C8;](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/subjects/behaviorsubject.js#L30-L37 "View in source")
54+
<a href="#rxbehaviorsubjectintialvalue">#</a> [&#x24C8;](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/subjects/behaviorsubject.js#L27-L34 "View in source")
5455

5556
Initializes a new instance of the `Rx.BehaviorSubject` class which creates a subject that caches its last value and starts with the specified value.
5657

@@ -92,7 +93,7 @@ subject.onCompleted();
9293
## _BehaviorSubject Instance Methods_ ##
9394

9495
### <a id="rxbehaviorsubjectprototypedispose"></a>`Rx.BehaviorSubject.prototype.dispose()`
95-
<a href="#rxbehaviorsubjectprototypedispose">#</a> [&#x24C8;](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/subjects/behaviorsubject.js#L97-L102 "View in source")
96+
<a href="#rxbehaviorsubjectprototypedispose">#</a> [&#x24C8;](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/subjects/behaviorsubject.js#L101-L106 "View in source")
9697

9798
Unsubscribe all observers and release resources.
9899

@@ -134,8 +135,58 @@ try {
134135

135136
* * *
136137

138+
### <a id="rxbehaviorsubjectprototypegetvalue"></a>`Rx.BehaviorSubject.prototype.getValue()`
139+
<a href="#rxbehaviorsubjectprototypegetvalue">#</a> [&#x24C8;](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/subjects/behaviorsubject.js#L44-L50 "View in source")
140+
141+
Gets the current value or throws an exception.
142+
Value is frozen after `onCompleted` is called.
143+
After `onError` is called always throws the specified exception.
144+
An exception is always thrown after `dispose` is called.
145+
146+
#### Returns
147+
*(Mixed)*: The initial `value` passed to the constructor until `onNext` is called; after which, the last value passed to `onNext`.
148+
149+
#### Example
150+
```js
151+
var subject = new Rx.BehaviorSubject(56);
152+
153+
console.log('Value is: ' + subject.getValue());
154+
155+
// => Value is: 56
156+
157+
subject.onNext(42);
158+
159+
console.log('Value is: ' + subject.getValue());
160+
161+
// => Value is: 42
162+
163+
subject.onCompleted();
164+
165+
subject.onNext(100);
166+
167+
console.log('Value is frozen: ' + subject.getValue());
168+
169+
// => Value is frozen: 42
170+
171+
subject.dispose();
172+
173+
try {
174+
subject.getValue();
175+
} catch (e) {
176+
console.log(e.message);
177+
}
178+
179+
// => Object has been disposed
180+
```
181+
182+
### Location
183+
184+
= rx.binding.js
185+
186+
* * *
187+
137188
### <a id="rxbehaviorsubjectprototypehasobservers"></a>`Rx.BehaviorSubject.prototype.hasObservers()`
138-
<a href="#rxbehaviorsubjectprototypehasobservers">#</a> [&#x24C8;](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/subjects/behaviorsubject.js#L44-L46 "View in source")
189+
<a href="#rxbehaviorsubjectprototypehasobservers">#</a> [&#x24C8;](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/subjects/behaviorsubject.js#L55 "View in source")
139190

140191
Indicates whether the subject has observers subscribed to it.
141192

src/core/subjects/behaviorsubject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
/**
3838
* Gets the current value or throws an exception.
3939
* Value is frozen after onCompleted is called.
40-
* After onError is called Value always throws the specified exception.
40+
* After onError is called always throws the specified exception.
4141
* An exception is always thrown after dispose is called.
42-
* @returns {Mixed} The initial value passed to the constructor until OnNext is called; after which, the last value passed to OnNext.
42+
* @returns {Mixed} The initial value passed to the constructor until onNext is called; after which, the last value passed to onNext.
4343
*/
4444
getValue: function () {
4545
checkDisposed(this);

ts/rx.binding-lite.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
declare module Rx {
99
export interface BehaviorSubject<T> extends Subject<T> {
10+
getValue(): T;
1011
}
1112

1213
interface BehaviorSubjectStatic {

0 commit comments

Comments
 (0)