mobxjs / mobx-angular

The MobX connector for Angular.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async Example

stephenlautier opened this issue · comments

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

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

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.

@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.