1.1.2 • Published 3 years ago

remotedata-re v1.1.2

Weekly downloads
79
License
MIT
Repository
github
Last release
3 years ago

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

1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago