Skip to content

Latest commit

 

History

History
46 lines (32 loc) · 1.22 KB

subject.md

File metadata and controls

46 lines (32 loc) · 1.22 KB

Subject

A special type of Observable which shares a single execution path among observers

Ultimate RxJS

Examples

Example 1: simple Subject

( Stackblitz )

// RxJS v6+
import { Subject } from 'rxjs';

const sub = new Subject();

sub.next(1);
sub.subscribe(x => {
  console.log('Subscriber A', x);
});
sub.next(2); // OUTPUT => Subscriber A 2
sub.subscribe(x => {
  console.log('Subscriber B', x);
});
sub.next(3); // OUTPUT => Subscriber A 3, Subscriber B 3 (logged from both subscribers)

Related Recipes

Additional Resources


📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/Subject.ts