Skip to content

[WEB UI] add and implement redux-promise-middleware in pairing folder#196

Open
achmadk wants to merge 2 commits intopyk:masterfrom
achmadk:master
Open

[WEB UI] add and implement redux-promise-middleware in pairing folder#196
achmadk wants to merge 2 commits intopyk:masterfrom
achmadk:master

Conversation

@achmadk
Copy link

@achmadk achmadk commented Dec 2, 2016

saya sudah menambahkan salah satu redux middleware yang bernama redux-promise-middleware. penggunaan middleware tersebut memudahkan para pengembang dalam mengambil data dari API. Contoh konkretnya

sebelum menggunakan redux-promise-middleware, pengembang menggunakan fungsi

export const fetchPairings = () => dispatch => {
   ajax.get('pairings').then((res) => {
      dispatch(setPairings(res.data))
    })
}

setelah menggunakan redux-promise-middleware, pengembang dapat memasukkan ajax.get(...) ke dalam payload

export const fetchPairings = () => ({
   type: SET_PAIRINGS,
   payload: ajax.get('pairings')
});

kemudian tambahkan action type _PENDING, _FULFILLED, dan REJECTED ke dalam reducer

export default (state = initialState, action = {}) => {
   const { type, payload } = action
   switch (type) {
       case `${SET_PAIRINGS}_PENDING`:
          return { ...state, loading_list: true };
       case `${SET_PAIRINGS}_FULFILLED`:
          return { ...state, loading_list: false, list: payload.data };
       case `${SET_PAIRINGS}_REJECTED`:
          return { ...state, loading_list: false, error: payload.error };
       ...

@pyk pyk added the tim-ui label Dec 3, 2016
Copy link
Contributor

@rrmdn rrmdn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants