All Projects → devexperts → Remote Data Ts

devexperts / Remote Data Ts

Licence: mpl-2.0
RemoteData type

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Remote Data Ts

Scriptum
A fool's scriptum on functional programming
Stars: ✭ 346 (+87.03%)
Mutual labels:  algebraic-data-types, functional-programming
Derive4j
Java 8 annotation processor and framework for deriving algebraic data types constructors, pattern-matching, folds, optics and typeclasses.
Stars: ✭ 511 (+176.22%)
Mutual labels:  algebraic-data-types, functional-programming
Poica
🧮 A research programming language on top of C macros
Stars: ✭ 231 (+24.86%)
Mutual labels:  algebraic-data-types, functional-programming
Fluture
🦋 Fantasy Land compliant (monadic) alternative to Promises
Stars: ✭ 2,249 (+1115.68%)
Mutual labels:  algebraic-data-types, functional-programming
Enum Fp
Functional Enum type / Sum type for javascript with simple pattern matching
Stars: ✭ 27 (-85.41%)
Mutual labels:  algebraic-data-types, functional-programming
Static Land
Specification for common algebraic structures in JavaScript based on Fantasy Land
Stars: ✭ 699 (+277.84%)
Mutual labels:  algebraic-data-types, functional-programming
Whyhaskellmatters
In this article I try to explain why Haskell keeps being such an important language by presenting some of its most important and distinguishing features and detailing them with working code examples. The presentation aims to be self-contained and does not require any previous knowledge of the language.
Stars: ✭ 418 (+125.95%)
Mutual labels:  algebraic-data-types, functional-programming
Cl Algebraic Data Type
Algebraic data types in Common Lisp
Stars: ✭ 86 (-53.51%)
Mutual labels:  algebraic-data-types, functional-programming
Purify
Functional programming library for TypeScript - https://gigobyte.github.io/purify/
Stars: ✭ 843 (+355.68%)
Mutual labels:  algebraic-data-types, functional-programming
Lambda
Functional patterns for Java
Stars: ✭ 737 (+298.38%)
Mutual labels:  algebraic-data-types, functional-programming
Imtools
Fast and memory-efficient immutable collections and helper data structures
Stars: ✭ 85 (-54.05%)
Mutual labels:  algebraic-data-types, functional-programming
Functionaljava
Functional programming in Java
Stars: ✭ 1,472 (+695.68%)
Mutual labels:  algebraic-data-types, functional-programming
Stegcloak
Hide secrets with invisible characters in plain text securely using passwords 🧙🏻‍♂️⭐
Stars: ✭ 2,379 (+1185.95%)
Mutual labels:  functional-programming
Fika
A statically typed functional programming language for the web.
Stars: ✭ 179 (-3.24%)
Mutual labels:  functional-programming
Akar
First-class patterns for Clojure. Made with love, functions, and just the right amount of syntax.
Stars: ✭ 176 (-4.86%)
Mutual labels:  functional-programming
Wiwinwlh
What I Wish I Knew When Learning Haskell
Stars: ✭ 2,250 (+1116.22%)
Mutual labels:  functional-programming
Potigol
Linguagem Potigol - Linguagem de programação funcional moderna para iniciantes - A Functional Programming Language for Beginners
Stars: ✭ 179 (-3.24%)
Mutual labels:  functional-programming
Iota
Fast [co]product types with a clean syntax. For Cats & Scalaz.
Stars: ✭ 175 (-5.41%)
Mutual labels:  functional-programming
Scala Workflow
Boilerplate-free syntax for computations with effects
Stars: ✭ 173 (-6.49%)
Mutual labels:  functional-programming
Curryable
An elegant and simple curry(f) implementation in PHP.
Stars: ✭ 172 (-7.03%)
Mutual labels:  functional-programming

RemoteData type Build Status

Description

RemoteData is an ADT (algebraic data type) described in this article. Heavily based on fp-ts lib.

Installation

npm i --save @devexperts/remote-data-ts

How to lift (wrap) your data in RemoteData:

As you remember RemoteData is an union of few types: RemoteInitial, RemotePending, RemoteFailure and RemoteSuccess.

While your data in initial or pending state just use initial or pending constant, because you don't have any real values in this case.

import { initial, pending } from '@devexperts/remote-data-ts';

const customers = initial;
// or
const customers = pending;

When you receive data from server, use failure or success function, it depends on what you received:

import { failure, success } from '@devexperts/remote-data-ts';
import { apiClient } from 'apiClient';
import { TCustomer } from './MyModel';

const getCustomers = (): RemoteData<TCustomer[]> => {
   const rawData: TCustomer[] = apiClient.get('/customers');

   try {
        const length = rawData.length;

        return success(rawData);
   }
   catch(err) {
        return failure(new Error('parse error'));
   }
}

How to fold (unwrap) your data from RemoteData:

Finally you pass data to the component and want to render values, so now it's time to get our values back from RemoteData wrapper:

import { NoData, Pending, Failure } from './MyPlaceholders';
import { TCustomer } from './MyModel';

type TCustomersList = {
    entities: RemoteData<TCustomer[]>;
};

const CustomersList: SFC<TCustomersList> = ({ entities }) => entities.foldL(
    () => <NoData />,
    () => <Pending />,
    err => <Failure error={err} />,
    data => <ul>{data.map(item => <li>{item.name}</li>)}</ul>
);

Docs & Examples

Coming soon (check the source)

Contributions

Publish

Don't forget to run npm run changelog and to commit the changes

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].