Last active
October 6, 2019 12:50
-
-
Save relekang/c4a87b737f21c1eae09515547df4e633 to your computer and use it in GitHub Desktop.
Helpers for working with ReasonUrql.Types.response
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
type t('a) = ReasonUrql.Types.response('a); | |
let map: (t('a), 'a => 'b) => t('b) = | |
(response, fn) => | |
switch (response) { | |
| Fetching => Fetching | |
| NotFound => NotFound | |
| Error(error) => Error(error) | |
| Data(data) => Data(fn(data)) | |
}; | |
let log: t('a) => unit = | |
response => | |
switch (response) { | |
| Fetching => Js.log("fetching") | |
| NotFound => Js.log("not found") | |
| Error(error) => Js.log2("error", error) | |
| Data(data) => Js.log2("data", data) | |
}; | |
let getWithDefault: (t('a), 'a) => React.element = | |
(response, default) => | |
switch (response) { | |
| Fetching => default | |
| NotFound => default | |
| Error(_) => default | |
| Data(data) => data | |
}; | |
let toElement: (t('a), 'a => React.element) => React.element = | |
(response, fn) => response | |
->map(fn) | |
->getWithDefault(React.null); | |
let isDone: t('a) => bool = | |
response => | |
switch (response) { | |
| Fetching => false | |
| NotFound => false | |
| Error(_) => true | |
| Data(_) => true | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment