remotedata-re

1.1.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i remotedata-re

Weekly Downloads

3

Version

1.1.2

License

MIT

Unpacked Size

28.3 kB

Total Files

15

Last publish

Collaborators

  • rvcas