mobxjs / mobx-angular

The MobX connector for Angular.
MIT License
483 stars 59 forks source link

Async Example #78

Closed stephenlautier closed 6 years ago

stephenlautier commented 6 years ago

Is it possible to create a simple example (or even modify one of your existing) to use some async add/get actions to better understand how will it work in real scenarios please?

Even if its a fake client such as

export interface Hero {
    key: string;
    name: string;
}

const HEROES_INITIAL: Hero[] = [
    { key: "rexxar", name: "Rexxar" },
    { key: "Malthael", name: "Malthael" },
    { key: "diablo", name: "Diablo" },
];

export class HeroClient {

    private heroes: Hero[] = [...HEROES_INITIAL];

    getAll(): Promise<Hero[]> {
        return Promise.resolve(HEROES_INITIAL);
    }

    add(hero: Hero): Promise<Hero> {
        this.heroes.push(hero);
        return Promise.resolve(hero);
    }

    remove(hero: Hero): Promise<{}> {
        this.heroes.splice(this.heroes.indexOf(hero), 1 );
        return Promise.resolve({});
    }

}

Thanks

adamkleingit commented 6 years ago

Hi, this is a general MobX question. A good place to get info about async flows is here: https://mobx.js.org/best/actions.html

All the best

stephenlautier commented 6 years ago

Yes i left it because you had 3 samples, and none contains a real scenario, especially with Angular. So I thought it would be good to have something like that. But thanks anyway.

adamkleingit commented 6 years ago

@stephenlautier The reasoning is that the integration of Angular to MobX is in a very thin layer of observing the store directly from the view. Everything else - is completely agnostic to Angular, and specific to MobX.