Last active
August 20, 2019 22:52
-
-
Save ozluy/5269f85b46fd26bb877370f4432d5dff to your computer and use it in GitHub Desktop.
models.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sayac modeli | |
export const sayac = { | |
state: { | |
yukleniyor: false, | |
deger: 0, | |
}, // saf hal/durum (initial state) | |
reducers: { | |
// saf fonksiyon | |
birEkle: state => ({ ...state, ...{ deger: state.deger + 1 } }), | |
yukleniyoruAyarla: (state, payload) => ({ ...state, ...{ yukleniyor: payload } }), | |
}, | |
effects: dispatch => ({ | |
// saf olmayan fonksiyonlarınız için burayı kullanın | |
// asenkron aksiyonlar (eg. API calls) için async/await kullanın | |
birEkleAsync: async () => { | |
dispatch.sayac.yukleniyoruAyarla(true) | |
await new Promise(resolve => setTimeout(resolve, 1000)) | |
dispatch.sayac.yukleniyoruAyarla(false) | |
dispatch.sayac.birEkle() | |
}, | |
}), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment