app.js 833 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import api from "api";
  2. export const TEST_ACTION = "TEST_ACTION";
  3. export const TEST_ASYNC_ACTION_START = "TEST_ASYNC_ACTION_START";
  4. export const TEST_ASYNC_ACTION_ERROR = "TEST_ASYNC_ACTION_ERROR";
  5. export const TEST_ASYNC_ACTION_SUCCESS = "TEST_ASYNC_ACTION_SUCCESS";
  6. export function testAction() {
  7. return {
  8. type: TEST_ACTION,
  9. };
  10. }
  11. function testAsyncStart() {
  12. return {
  13. type: TEST_ASYNC_ACTION_START,
  14. };
  15. }
  16. function testAsyncSuccess(data) {
  17. return {
  18. type: TEST_ASYNC_ACTION_SUCCESS,
  19. data,
  20. };
  21. }
  22. function testAsyncError(error) {
  23. return {
  24. type: TEST_ASYNC_ACTION_ERROR,
  25. error,
  26. };
  27. }
  28. export function testAsync() {
  29. return function (dispatch) {
  30. dispatch(testAsyncStart());
  31. api.testAsync()
  32. .then(data => dispatch(testAsyncSuccess(data)))
  33. .catch(error => dispatch(testAsyncError(error)));
  34. };
  35. }
  36. // Update