Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

rvcas/remotedata-re

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RemoteData

npm version Build Status license

For some background, read this post

Installation

npm install remotedata-re

# or yarn

yarn add remotedata-re

Then add it to bsconfig.json

{
  "bs-dependencies": [
    "remotedata-re"
  ]
}

Usage

type data = list(string);
type error = string;
type remoteData = RemoteData.t(data, data, error);

let debugLog = (v: remoteData) =>
  switch (v) {
  | RemoteData.NotAsked => "Not Asked"
  | Loading(previous) =>
    let s = Js.Array.joinWith(", ", previous->Belt.List.toArray);
    {j|Loading ($s)|j};
  | Success(data) =>
    let s = Js.Array.joinWith(" + ", data->Belt.List.toArray);
    {j|Success ($s)|j};
  | Failure(_error) => "Failure"
  };

Js.log(RemoteData.NotAsked->debugLog);
/* output: Not Asked */

Js.log(RemoteData.Loading(["foo", "bar"])->debugLog);
/* output: Loading (foo, bar)*/

Js.log(RemoteData.Success(["foo", "bar", "baz"])->debugLog);
/* output: Success (foo + bar + baz)*/

Js.log(RemoteData.Failure("oops")->debugLog);

Examples

Note

Inspiration: remotedata