devexperts / remote-data-ts Goto Github PK
View Code? Open in Web Editor NEWRemoteData type
License: Mozilla Public License 2.0
RemoteData type
License: Mozilla Public License 2.0
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
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?
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:
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?
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
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.
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))
);
Looks like recent updates to popover tracking on container scoll (with capturing) break popovers with scrollable inside.
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.
fp-ts
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?
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.
I think I found a bug while trying to upgrade this library to fp-ts@2
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
io-ts-types@latest
src/remote-data-io.ts
in VSCode or try to compile the project, shouldn't type checkI want to record the progress of an (upload) request, however currently RemotePending
does not store any value for itself.
Example of a remote data type which has this: https://github.com/cyclejs-community/cycle-remote-data
https://github.com/cyclejs-community/cycle-remote-data#whencases-casest-u-u
Related krisajenkins/remotedata#25
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".
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?
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
?
index.ts
should reexport as namespaces: export * as remoteData from './remote-data
instead of unnamed exports.index.ts
should reexport remote-data-t
as wellimport { remoteData } from '@devexperts/remote-data-ts'
)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;
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?
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.
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.
As per gcanti/fp-ts#1241, fp-ts
now allows imports without /lib
or /es6
paths, e.g.
import * as O from 'fp-ts/Option';
instead of
import * as O from 'fp-ts/lib/Option';
or
import * as O from 'fp-ts/es6/Option';
Perhaps we could make the same change to this library. WDYT?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.