• Stars
    star
    288
  • Rank 143,818 (Top 3 %)
  • Language
    TypeScript
  • License
    Mozilla Public Li...
  • Created over 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RemoteData type

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

More Repositories

1

aprof

Java memory allocation profiler
Java
218
star
2

lin-check

Linearization checker for Java concurrent programs
Java
104
star
3

dlcheck

Potential deadlocks checker
Java
83
star
4

swagger-codegen-ts

Typesafe Swagger API generator for TypeScript
TypeScript
80
star
5

QD

Quote Distribution Subsystem
Java
54
star
6

dxcharts-lite

Flexible financial charts based on HTML5 canvas
TypeScript
44
star
7

dx-platform

TypeScript
33
star
8

time-test

Framework for testing time-dependent functionality
Java
32
star
9

suitcase

SUITCase can verify screenshots in five different ways while testing the User Interface of iOS, iPadOS, and tvOS apps in Simulator. It has been designed to be used with XCTest and written in Swift.
Swift
21
star
10

jagent

Java
15
star
11

gwtscript

TypeScript
15
star
12

grading-system

Grades system for the engineers at Devexperts
14
star
13

egen

EGEN - Externalizable implementation generator
Java
14
star
14

usages

Usages analysis tool
Java
13
star
15

switchboard

Toolset designed to collect, parse, filter and group automated tests from code, transform the result and perform the required further actions.
Java
13
star
16

screenobject

ScreenObject implements ScreenObject (PageObject) pattern in your tests. It also automatically generates classes with screen's elements. ScreenObject is useful in User Interface testing of iOS, iPadOS, tvOS and macOS.
Swift
11
star
17

bintray-maven-plugin

Java
10
star
18

interview-public

interview-public
Java
6
star
19

chameleon

Chameleon - Color Palette Management Tool
Java
5
star
20

objctify

Ruby
4
star
21

uilocalizer

Java
4
star
22

dgen

Java
3
star
23

TDP

Thread Dump Parser
Java
3
star
24

uilagfinder

UI-Lag-Finder tool for detecting potential lags in UI thread via run-time and static analysis
1
star