Coder Social home page Coder Social logo

remote-data-ts's People

Contributors

dependabot[bot] avatar fes300 avatar jeeronimoo avatar joshburgess avatar larskinn avatar leighman avatar mankdev avatar nikolaenkov avatar oliverjash avatar poteto avatar raveclassic avatar scink avatar scotttrinh avatar ybogomolov avatar zugaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

remote-data-ts's Issues

Rewrite imports in `es6` folder

Currently the imports in the es6 folder reference fp-ts/lib when they should reference fp-ts/es6 (so that tree shaking can work properly), e.g.

https://unpkg.com/browse/@devexperts/[email protected]/es6/remote-data.js

import { constFalse, identity, constant } from 'fp-ts/lib/function';

This change has recently been made to other libraries such as io-ts and fp-ts-rxjs, for example: gcanti/fp-ts-rxjs@f35c926

https://unpkg.com/browse/[email protected]/es6/Observable.js

Related issue: gcanti/fp-ts#1044

Question about pending state

How to separate state when I do first loading, and show skeleton, and second+ loading, when I don't want to hide my content, is it possible?

sequenceS and sequenceT from fp-ts Apply gives type errors

I'm not sure if this is an upstream bug in fp-ts, or if something is wrong with the implementation here.

I would expect sequenceS and sequenceT to work like they do for Either, but instead I get type errors.

import * as remoteData from "@devexperts/remote-data-ts/es6/remote-data";
import { apply, either } from "fp-ts/es6";

export const sequenceSEither = apply.sequenceS(either.either) // WORKS
export const sequenceSRemoteData = apply.sequenceS(remoteData.remoteData) // Error: No overload matches this call.
export const sequenceTEither = apply.sequenceT(either.either) // WORKS
export const sequenceTRemoteData = apply.sequenceT(remoteData.remoteData) // Error: No overload matches this call.

The full error in both cases is:

No overload matches this call.
  The last overload gave the following error.
    Argument of type 'Monad2<"RemoteData"> & Foldable2<"RemoteData"> & Traversable2<"RemoteData"> & Bifunctor2<"RemoteData"> & Alt2<"RemoteData"> & Extend2<...> & Alternative2<...>' is not assignable to parameter of type 'Apply<"RemoteData">'.
      Types of property 'ap' are incompatible.
        Type '<E, A, B>(fab: RemoteData<E, (a: A) => B>, fa: RemoteData<E, A>) => RemoteData<E, B>' is not assignable to type '<A, B>(fab: HKT<"RemoteData", (a: A) => B>, fa: HKT<"RemoteData", A>) => HKT<"RemoteData", B>'.
          Types of parameters 'fab' and 'fab' are incompatible.
            Type 'HKT<"RemoteData", (a: A) => B>' is not assignable to type 'RemoteData<unknown, (a: unknown) => unknown>'.
              Type 'HKT<"RemoteData", (a: A) => B>' is missing the following properties from type 'RemoteSuccess<(a: unknown) => unknown>': _tag, valuets(2769)
Apply.d.ts(292, 25): The last overload is declared here.

Here is a more elaborate codesandbox demonstrating the problem:

question about representing "pending+data" state

Have you avere considered adding a case representing a state where we have some data (success or failure that is) and also we are re-fetching a remote resource?

I've never used this library so I must be missing something, but the need for this case comes up from time to time in the applications I work on, e.g. show some data but also notify the user with a "soft loading"/"syncing" state.

Any suggestion on how this could be approached with remote-data-ts?

'io-ts' and 'io-ts-types' are missing

because of remote-data-io.ts import in index.ts packages io-ts and io-ts-types became required. but they are in peerDependencies and NPM doesn't install them. that forces to install unnecessary for project packages manually. removing index.ts will fix it

Remove RemoteInitial state

In practice RemoteInitial doesn't represent any useful data state. Historically it was introduced basing on the article and to describe initial value in angular2 property bindings in classes.
However in 100% cases initial state is actually RemotePending.

This issue should gain some feedback before removing.

Add monocle-ts Optional

What do you think about adding support for monocle-ts via an Optional?

const RemoteDataOptional = <L, R>() => new Optional<RemoteData<L, R>, R>(
  s => s.toOption(),
  a => s => s.fold(s, s, () => s, () => success(a))
);

Popovers with Scrollable inside are immediately closed when opened

Looks like recent updates to popover tracking on container scoll (with capturing) break popovers with scrollable inside.

  • popover is opened
  • scrollCapture handler is attached to container (window by default)
  • Scrollable is mounted and resize-detector is attached using ScrollStrategy which emits scroll event when installed
  • scroll event inside popover is captured by handler
  • popover is immediately closed

Provide version with ES modules

fp-ts provides a version with ES modules (specified via module in package.jon), which means tree shaking can work.

What do you think about doing the same thing for this package?

For context: I have a PR to add this library to unsplash.com, but I noticed it's currently bundling all of io-ts (because IIUC, tree shaking can't work with CommonJS), even though we're not using any of the io-ts helpers.

Versioning

So we are close to releasing [email protected] compatible RemoteData right now and it's a massive breaking change. We (and community) definitely won't be able to migrate all the projects soon so we need to support [email protected] version for a while.

We need the ability to release patches and minors for both versions so it looks like we have to release separate majors for both fp-ts versions: [email protected] and [email protected].

Any concerns?

fp-ts@2

Are there any plans to port this library to fp-ts@2? I could provide a pull request to make it both fp-ts@1 and fp-ts@2 compatable.

Possible bug in remote-data-io.ts

I think I found a bug while trying to upgrade this library to fp-ts@2

Here

JSONProgress.encode outputs a { loaded: number; total: number | null; } | null but should be a RemoteProgress | null and RemoteProgress is defined as

export type RemoteProgress = {
  loaded: number;
  total: Option<number>;
};

Repro

  • install io-ts-types@latest
  • open src/remote-data-io.ts in VSCode or try to compile the project, shouldn't type check

`TaskRemoteData`

Hello I'm trying to migrate from Either to RemoteData but I find hard to replace TaskEither. I was wonder if is possible to add a TaskRemoteData type. I tried myself (fp newbie) and I have something working (for my specific usage) but it isn't very complete (it doesn't even fully satisfy Monad type).

As non-advanced user take my words with care, maybe I don't have the right "perspective".

RemoteData Applicative ordering

Currently, the applicative priority of RemoteData is initial > (pending, failure, success). Example:

// Outputs "Initial"
sequence(remoteData, array)([
  initial,
  pending,
  failure({}),
  success({}),
])

It makes more sense that any failure should result in failure. Then, any pending, then initial, and finally success.

Thoughts?

Synthetic fold

hi @raveclassic,
first of all, thank you for this piece of code, it defines a very complete and clean interface for dealing with IO data.

In most of the apps I design, when I fetch data the initial case does not need to be handled (data is fetched as soon as a view is loaded so I want to handle only the loading, failure and success cases). As this is true for 95% of my use cases, it seems a bit overkill to fold on my data structures as it forces me to handle separately the loading and initial case but at the same time, I would like to keep the strictness for all other cases.
How would you feel about a syntheticFold method that merges the handling of initial and loading?

Update index exports

  • index.ts should reexport as namespaces: export * as remoteData from './remote-data instead of unnamed exports.
  • index.ts should reexport remote-data-t as well
    This will enable whole-module autoimports from IDE (i.e. import { remoteData } from '@devexperts/remote-data-ts')

fold pending parameter should provide progress

Currently it is not possible to access the progress inside the fold and foldL method.

Expected:

fold<B>(initial: B, pending: Function1<Option<RemoteProgress>, B>, failure: Function1<L, B>, success: Function1<A, B>): B;

foldL<B>(initial: Lazy<B>, pending: Function1<Option<RemoteProgress>, B>, failure: Function1<L, B>, success: Function1<A, B>): B;

Suggestion: constructors should receive all generics

Currently we have this problem:

import * as RemoteData from '@devexperts/remote-data-ts';
import { pipe } from 'fp-ts/function';

declare const fa: RemoteData.RemoteData<string, number>;
pipe(
    // error
    /*
    Argument of type 'RemoteData<string, number>' is not assignable to parameter of type 'RemoteData<never, number>'.
      Type 'RemoteFailure<string>' is not assignable to type 'RemoteData<never, number>'.
        Type 'RemoteFailure<string>' is not assignable to type 'RemoteFailure<never>'.
          Type 'string' is not assignable to type 'never'.
    */
    fa,
    RemoteData.chain((a) => RemoteData.success(a)),
);

This is not a problem when we use Either from fp-ts:

import * as Either from 'fp-ts/Either';
import { pipe } from 'fp-ts/function';

declare const fa: Either.Either<string, number>;
pipe(
    // no error
    fa,
    Either.chain((a) => Either.right(a)),
);

The reason this works with Either is because right receives the E generic:

export declare const right: <E = never, A = never>(a: A) => Either<E, A>

However the same cannot be said for RemoteData.successβ€”it does not receive the E generic:

export declare const success: <A>(value: A) => RemoteData<never, A>;

It's an easy fix:

-export declare const success: <A>(value: A) => RemoteData<never, A>;
+export declare const success: <E = never, A = never>(value: A) => RemoteData<E, A>;

We would make the same change to other constructors like failure.

Would you accept a PR for this?

Instance method `.toEither`

Any thoughts on adding an instance method that maps RemoteData<L, A> to Either<L, A>? I'd be happy to throw a PR together.

Add "recover" method

Sometime we need to process RemoteFailure and return RemoteSuccess with some boolean flag, for example process RemoteFailure<AjaxError, boolean> 401 status and return const isAuthorized = success(false).

We should add a method called recover (may be discussed) accepting a callback transforming error to smth valueable. Similar to Filterable.filterMap such callback should return Some when transformation is applicable and None when not.
Type signature should be:
recover: RemoteData<L, A> ~> (f: (l: L) => Option<A>) => RemoteData<L, A>
Possible implementation for RemoteFailure<L, A>:

recover: (f: (l: L) => Option<A>) => {
  const result = f(this.error)
  return result.isSome() ? success<L, A>(result.value) : this
}

For RemoteInitial, RemotePending, RemoteSuccess should return self.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.