Skip to content

Instantly share code, notes, and snippets.

@Nkzn
Created June 27, 2018 14:31
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 Nkzn/a8ac4796fc9060623f905ebb9c335d5b to your computer and use it in GitHub Desktop.
Save Nkzn/a8ac4796fc9060623f905ebb9c335d5b to your computer and use it in GitHub Desktop.
import { doHoge, doFuga, addFoo, addBar } from "../ducks";
class ApplicationService {
constructor(private dispatch: Dispatch, private client: ApiClient) {
}
async getHoge(id: number) {
const hoge = await this.client.fetchHoge(id);
this.dispatch(doHoge(hoge.id));
const fuga = await this.client.fetchFuga(hoge.id);
this.dispatch(doFuga(fuga.id, hoge.name));
}
getFoo() {
this.dispatch(async (dispatch, getState) => {
const {foo, bar} = getState();
dispatch(addFoo(foo + 1));
dispatch(addBar(bar + 1));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment