Skip to content

Instantly share code, notes, and snippets.

@amrfarid140
Created July 11, 2018 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amrfarid140/8ff355442c533b89e52276dc63ad3b87 to your computer and use it in GitHub Desktop.
Save amrfarid140/8ff355442c533b89e52276dc63ad3b87 to your computer and use it in GitHub Desktop.
View Model
import { action, observable } from "mobx";
import { IRepositroy } from "../data/models/Repository";
import { ViewRepositoriesUseCase } from "../domain/ViewRepositoriesUseCase";
export class AppViewModel {
@observable public items: IRepositroy[] = [];
@observable public errors: string[] = [];
private readonly useCase: ViewRepositoriesUseCase;
constructor(useCase: ViewRepositoriesUseCase) {
this.useCase = useCase;
this.prepare();
}
@action.bound
public refresh() {
this.useCase.fetchMore().subscribe(undefined, error => {
this.errors.push(error.message);
});
}
@action.bound
public async clearData() {
await this.useCase.clearItems();
}
@action.bound
private prepare() {
this.useCase.observeItems().subscribe(
items => {
this.items = items;
},
error => {
this.errors.push(error.message);
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment