## ReplaySource ```ts interface IReplaySourceMethods { getValues(): readonly GValue[]; } type IReplaySource> = Omit> & IReplaySourceMethods; ``` ```ts function createReplaySource>( source: GSource, maxNumberOfValues: number = Number.POSITIVE_INFINITY, ): IReplaySource ``` A *ReplaySource* is used to cache many values and emit them each time we subscribe to it. When calling `createReplaySource` you must provide a `source` which is used to build the ReplaySource. You may choose for example, between an *UnicastSource* or a *MulticastSource*. This is equivalent to the *[ReplaySubject](https://rxjs.dev/api/index/class/ReplaySubject)* if you provide a *MulticastSource*. ### Extra - shortcut functions ```ts function createMulticastReplaySource( maxNumberOfValues?: number, ): IMulticastReplaySource ``` ```ts function createUnicastReplaySource( maxNumberOfValues?: number, ): IUnicastReplaySource ``` ### Examples #### ReplaySource ```ts const source = createMulticastReplaySource(); source.subscribe((value: string) => { console.log('value - A:', value); }); source.emit(0); source.emit(1); source.subscribe((value: string) => { console.log('value - B:', value); }); source.emit(2); ``` Output: ```text value - A: 0 value - A: 1 value - B: 0 value - B: 1 value - A: 3 value - B: 3 ``` ##### RxJS equivalent ```ts const source = new ReplaySubject(); source.subscribe((value: string) => { console.log('value - A:', value); }); source.next(0); source.next(0); source.subscribe((value: string) => { console.log('value - B:', value); }); source.next(2); ```