Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "recover" method #12

Closed
raveclassic opened this issue Sep 21, 2018 · 0 comments · Fixed by #14
Closed

Add "recover" method #12

raveclassic opened this issue Sep 21, 2018 · 0 comments · Fixed by #14
Assignees
Labels

Comments

@raveclassic
Copy link
Contributor

raveclassic commented Sep 21, 2018

Sometime we need to process RemoteFailure and return RemoteSuccess with some boolean flag, for example process RemoteFailure<AjaxError, boolean> 401 status and return const isAuthorized = success(false).

We should add a method called recover (may be discussed) accepting a callback transforming error to smth valueable. Similar to Filterable.filterMap such callback should return Some when transformation is applicable and None when not.
Type signature should be:
recover: RemoteData<L, A> ~> (f: (l: L) => Option<A>) => RemoteData<L, A>
Possible implementation for RemoteFailure<L, A>:

recover: (f: (l: L) => Option<A>) => {
  const result = f(this.error)
  return result.isSome() ? success<L, A>(result.value) : this
}

For RemoteInitial, RemotePending, RemoteSuccess should return self.

@raveclassic raveclassic self-assigned this Sep 21, 2018
raveclassic added a commit that referenced this issue Sep 21, 2018
raveclassic added a commit that referenced this issue Sep 25, 2018
raveclassic added a commit that referenced this issue Sep 25, 2018
raveclassic added a commit that referenced this issue Sep 25, 2018
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 a pull request may close this issue.

1 participant