All Projects → FabienHenon → bs-remotedata

FabienHenon / bs-remotedata

Licence: other
RemoteData and WebData to use with bs-fetch for BuckleScript

Programming Languages

ocaml
1615 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to bs-remotedata

remotedata-re
Tools for fetching data from remote sources in Reason
Stars: ✭ 32 (+77.78%)
Mutual labels:  reasonml, remotedata
bs-declaredom
Strongly typed declarative markup for the DOM and CSS
Stars: ✭ 66 (+266.67%)
Mutual labels:  reasonml
Relude
FP-inspired prelude/standard library for ReasonML projects
Stars: ✭ 230 (+1177.78%)
Mutual labels:  reasonml
zestdb
ZestDB
Stars: ✭ 18 (+0%)
Mutual labels:  reasonml
Re Web
Experimental web framework for ReasonML & OCaml
Stars: ✭ 237 (+1216.67%)
Mutual labels:  reasonml
app-template-rescript-react
Adding ReScript with rescript-react on top of @snowpack/app-template-react
Stars: ✭ 44 (+144.44%)
Mutual labels:  reasonml
Lwt Node
Reason Implementation of Node.js API ✨🏎🚀✨
Stars: ✭ 226 (+1155.56%)
Mutual labels:  reasonml
reason-react-native-example
ReasonML React Native (Expo) example
Stars: ✭ 14 (-22.22%)
Mutual labels:  reasonml
bs-spectacle
No description or website provided.
Stars: ✭ 15 (-16.67%)
Mutual labels:  reasonml
bs-rsuite-ui-react
Reason bindings for React Suite UI library
Stars: ✭ 26 (+44.44%)
Mutual labels:  reasonml
Reason Graphql Fullstack
Fullstack Reason + GraphQL Todo List App
Stars: ✭ 246 (+1266.67%)
Mutual labels:  reasonml
granary
Tezos smart contract & dapp development toolkit
Stars: ✭ 67 (+272.22%)
Mutual labels:  reasonml
RemoteDataK
Algebraic data type (ADT) to represent the state of data that is loading from/to remote sources/destinations
Stars: ✭ 44 (+144.44%)
Mutual labels:  remotedata
Klipse
Klipse is a JavaScript plugin for embedding interactive code snippets in tech blogs.
Stars: ✭ 2,841 (+15683.33%)
Mutual labels:  reasonml
hypatia
Convert JavaScript doctrings (in jsdoc AST format) to ijavascript Jupyter Notebooks
Stars: ✭ 12 (-33.33%)
Mutual labels:  reasonml
Wonder.js
🚀Functional, High performance 3D Webgl Engine
Stars: ✭ 225 (+1150%)
Mutual labels:  reasonml
rr-2048
2048 game in Reason React
Stars: ✭ 15 (-16.67%)
Mutual labels:  reasonml
lwt-node-starter
A simple starter for lwt-node
Stars: ✭ 13 (-27.78%)
Mutual labels:  reasonml
reasonml-idea-plugin
ReasonML Language Plugin for IDEA
Stars: ✭ 320 (+1677.78%)
Mutual labels:  reasonml
reason-epitath
CPS sugar usage for React Render Props composition in ReasonML
Stars: ✭ 16 (-11.11%)
Mutual labels:  reasonml

bs-remotedata

RemoteData and WebData to use with bs-fetch and bs-json for BuckleScript

Test status

RemoteData.t is a simple variant type that allows you to store a data that can have 4 potential states:

  • Success('a): your data has been successfully retrieved and stored
  • Failure('e): your data could not be retrieved
  • Loading: your data is beeing fetched
  • NotAsked: you didn't fetch your data yet

This type provides you many usefull functions to handle your data: map, andThen, withDefault, fromOption, fromResult, fromPromise, ...

The main goal for this type is to be used for HTTP requests. That's where WebData comes into play. WebData.t is a RemoteData.t type but with the error type specified as a WebData.error. The WebData module provides some usefull functions to fetch data from API and convert it to a WebData.t. You can even provide your own Json decoder to convert the result of your API call to a WebData.t of any type you want/need.

Example

type person = {
  age: int,
  name: string
};

module Decode = {
  let personDecoderExn = json =>
    Json.Decode.{
      age: json |> field("age", int),
      name: json |> field("name", string)
    };
    
  let personDecoder = json =>
    try (Belt.Result.Ok(personDecoderExn(json))) {
    | Json.Decode.DecodeError(err) => Belt.Result.Error(err)
    };    
};

/* At app launch say you set your data state to `NotAsked` */
let data: WebData.t(person) = RemoteData.NotAsked;

/* You received an event and you need to retrieve your data */
let data: WebData.t(person) = RemoteData.Loading;

Fetch.fetch("http://my-api")
|> WebData.fromResponse(Decode.personDecoder)
|> Js.Promise.then_(data => {
  /* Here your data is still a WebData.t(person) and will be
    either Success(person), or Failure(httpError) */
});

Installation

npm install --save bs-remotedata

Then add bs-remotedata to bs-dependencies in your bsconfig.json:

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

Documentation

For the moment, please see the interface files:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].