is-checks
This is just a POC and has NO real thoughts behind it.
This is basiaclly eventual-values with some extra methods that I wanted.
See:
example
if ( isError(state) ) {
return <Error message={ state } />
}
else if ( isPending(state) ) {
return <Spinner />
}
else if ( isData(state) ) {
return !isEmpty(state) ? state.map(item => <Item />) : <div>No items to display</div> :
}
values
val | isOk(val) | isData(val) | isEmpty(val) | isPending(val) | isError(val) |
---|---|---|---|---|---|
undefined |
false | false | true | true | false |
null |
true | false | true | false | false |
1 (number) |
true | true | false | false | false |
'' (empty string) |
true | true | true | false | false |
'name' (string) |
true | true | false | false | false |
[] or {}
|
true | true | true | false | false |
[1] or { value: true }
|
true | true | false | false | false |
throw Error() or Promise.reject()
|
false | false | true | false | true |