Skip to content

Instantly share code, notes, and snippets.

@Komock
Created September 23, 2021 06:32
Show Gist options
  • Save Komock/142c9c919a19a4d11848278f4d4c2d8c to your computer and use it in GitHub Desktop.
Save Komock/142c9c919a19a4d11848278f4d4c2d8c to your computer and use it in GitHub Desktop.
View state from BehaviorSubject
export class ViewState<T extends object> extends BehaviorSubject<T> {
constructor(initialState: T) {
super(initialState);
}
patch(newState: Partial<T>) {
this.next({
...this.value,
...newState
});
}
set(newState: T) {
this.next(newState);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment