This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { expect } from "chai"; | |
| import { produce } from "immer"; | |
| const current = [42]; | |
| const next = produce(current, draft => { draft.push(54); }); | |
| expect(current).to.deep.equal([42]); | |
| expect(next).to.deep.equal([42, 54]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createAction, createReducer, props } from "@ngrx/store"; | |
| import { on } from "ts-action-immer"; | |
| const add = createAction("[Todos] Add", props<{ text: string }>()); | |
| const reset = createAction("[Todos] Reset"); | |
| type Todo = { | |
| done: boolean; | |
| text: string; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createAction, createReducer, on, props } from "@ngrx/store"; | |
| const add = createAction("[Todos] Add", props<{ text: string }>()); | |
| const reset = createAction("[Todos] Reset"); | |
| type Todo = { | |
| done: boolean; | |
| text: string; | |
| }; | |
| const initialState = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| call(subscriber: Subscriber<R>, source: Observable<any>) { | |
| const { selector } = this; | |
| const subject = this.subjectFactory(); | |
| const subscription = selector(subject).subscribe(subscriber); | |
| subscription.add(source.subscribe(subject)); | |
| return subscription; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { concat, OperatorFunction, race, SchedulerLike, timer } from "rxjs"; | |
| import { mapTo, publish } from "rxjs/operators"; | |
| function startWithTimeout<T, S = T>( | |
| value: S, | |
| duration: number | Date, scheduler?: SchedulerLike | |
| ): OperatorFunction<T, S | T> { | |
| return source => source.pipe(publish(published => race( | |
| published, | |
| concat(timer(duration, scheduler).pipe(mapTo(value)), published) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { concat, of, race, timer } from "rxjs"; | |
| import { delay, mapTo, publish } from "rxjs/operators"; | |
| const source = of(42).pipe(delay(100)); | |
| const composed = source.pipe( | |
| publish(published => race( | |
| published, | |
| concat(timer(10).pipe(mapTo(54)), published) | |
| )) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { concat, ConnectableObservable, of, race, timer } from "rxjs"; | |
| import { delay, mapTo, publish } from "rxjs/operators"; | |
| const source = of(42).pipe(delay(100)); | |
| const published = source.pipe( | |
| publish() | |
| ) as ConnectableObservable<number>; | |
| const composed = race( | |
| published, | |
| concat(timer(10).pipe(mapTo(54)), published) |