Created
April 30, 2020 13:19
-
-
Save pvpshoot/d8623e25678f5d8f17c915a58b2bf4f8 to your computer and use it in GitHub Desktop.
This file contains 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
import { types } from 'mobx-state-tree'; | |
const StatusModel = types | |
.model('StatusModel', { | |
statusValue: types.optional(types.enumeration('status', ['initial', 'loading', 'success', 'failed']), 'initial'), | |
statusResponseReasonMessage: types.maybe(types.string), | |
}) | |
.views(self => ({ | |
get isInitial() { | |
return self.statusValue === 'initial'; | |
}, | |
get isLoading() { | |
return self.statusValue === 'loading'; | |
}, | |
get isSuccess() { | |
return self.statusValue === 'success'; | |
}, | |
get isFailed() { | |
return self.statusValue === 'failed'; | |
}, | |
})) | |
.actions(self => ({ | |
setStatus(status, reason) { | |
self.setResponseMessage(reason); | |
self.statusValue = status; | |
}, | |
initial(reason) { | |
self.setStatus('initial', reason); | |
}, | |
loading(reason) { | |
self.setStatus('loading', reason); | |
}, | |
success(reason) { | |
self.setStatus('success', reason); | |
}, | |
failed(reason) { | |
self.setStatus('failed', reason); | |
}, | |
setResponseMessage(reason) { | |
self.statusResponseReasonMessage = reason; | |
}, | |
})); | |
export default StatusModel; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment