Home Reference Source Repository
import {BehaviorSubject} from 'rxstream/src/subjects/behaviourSubject.js'
public class | source

BehaviorSubject

Extends:

Subject → BehaviorSubject

BehaviorSubject extends Subject. As Subject is a stream of values, BehaviorSubject is also a stream, but a little bit different. The difference is that BehaviorSubject remembers the last value that's been sent to it, and it sends this value to new subscribers. Take a look at example.

Example:

import { BehaviorSubject } from 'rxstream';

let stream$ = new BehaviorSubject();
stream$.next(1);
stream$.next(2);

stream$.subscribe(value => console.log(value));
stream$.next(3);
stream$.next(4);

// Output is going ot be: 2,3,4

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

next(data: any)

Send value to the stream

public

Subscribe to the stream

Inherited Summary

From class Subject
public

next(data: any)

Send value to the stream

public

Subscribe to the stream

public

subscriptionList(subscriptionList: *): *

public

unsubscribe(subscription: Subscription)

Unsubscribe from the stream

Public Constructors

public constructor() source

Override:

Subject#constructor

Public Methods

public next(data: any) source

Send value to the stream

Override:

Subject#next

Params:

NameTypeAttributeDescription
data any

Any value

public subscribe(callback: function): Subscription source

Subscribe to the stream

Override:

Subject#subscribe

Params:

NameTypeAttributeDescription
callback function

Return:

Subscription