Created
July 11, 2018 20:17
-
-
Save amrfarid140/8ff355442c533b89e52276dc63ad3b87 to your computer and use it in GitHub Desktop.
View Model
This file contains 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 { 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