Skip to content

Commit

Permalink
feat: add state$ and getState
Browse files Browse the repository at this point in the history
affects: @userlike/messenger-types
  • Loading branch information
anilanar committed Aug 25, 2020
1 parent 8baeece commit 881d8f1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
36 changes: 36 additions & 0 deletions packages/messenger-types/src/Observable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* This is the interface for observables as defined in
* https://github.com/tc39/proposal-observable. It's a proposal, but lots of
* libraries implement this interface. Most prominent one is rxjs, which is also
* used by Angular.
*/
export interface Observable<T> {
// Subscribes to the sequence with an observer
subscribe(observer: Observer<T>): Subscription;

// Subscribes to the sequence with callbacks
subscribe(
onNext: (v: T) => void,
onError?: (err: unknown) => void,
onComplete?: () => void
): Subscription;
}

export interface Subscription {
// Cancels the subscription
unsubscribe(): void;

// A boolean value indicating whether the subscription is closed
closed: boolean;
}

export interface Observer<T> {
// Receives the next value in the sequence
next(value: T): void;

// Receives the sequence error
error(errorValue: unknown): void;

// Receives a completion notification
complete(): void;
}
18 changes: 17 additions & 1 deletion packages/messenger-types/src/versions/v1.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { ActionResult } from "../ActionResult";
import { Observable } from "../Observable";

export interface Api extends ApiActions {
export interface Api extends ApiActions, ApiState {
version: 1;
}

export enum UI {
Hidden = "hidden",
Minimized = "minimized",
Maximized = "maximized",
}

export interface State {
ui: UI;
}

export interface ApiState {
state$: Observable<State>;
getState(): State;
}

export interface ApiActions {
/**
* Render the messenger.
Expand Down

0 comments on commit 881d8f1

Please sign in to comment.