cyclejs / collection

An easier way to do collections in Cycle.js
MIT License
60 stars 10 forks source link

Typescript definition #26

Open aravantv opened 8 years ago

aravantv commented 8 years ago

Hi,

would be great to have a typescript definition file. I think it's hard to make it perfect due to the fact that cyclejs tries to be stream-library independent (entailing no one-type for streams), but at least a pragmatic typing which would just prevent having "unknown module" errors when using collections.

The following one could be a basis I believe:

export declare type Component<So, Si> = (sources: So, ...rest: Array<any>) => Si;

export declare interface Collection {
  <So, Si, StreamSi> (component: Component<So, Si>, sources?: So, add$?: StreamSi, remove$?: (item: Component<So, Si>) => any): Component<So, Si>;
  pluck (items$: any, f: (item: any) => any) : any;
}

export declare const Collection: Collection;
export default Collection
aravantv commented 8 years ago

Mmmh I see that collection needs xstream anyways, so I could even make the types dependent on Stream.

Widdershin commented 8 years ago

I welcome a definition, are you interested in doing a pull request?

A full TypeScript rewrite has been on the cards for a while. If someone is keen to get stuck into that I would be happy to support them.

aravantv commented 8 years ago

Sure, I will work it properly and do a pull request. Do you confirm that a dependency on xstream is no problem?

Widdershin commented 8 years ago

I'm not sure, I'm no TypeScript expert. It's worth noting that collection is stream library agnostic, via adapters. So it's not just xstream only.

On 25/10/2016 10:28 AM, "Vincent Aravantinos" notifications@github.com wrote:

Sure, I will work it properly and do a pull request. Do you confirm that a dependency on xstream is no problem?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cyclejs/collection/issues/26#issuecomment-255871424, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYUHaRKiBJZDPd_74CtrCgsbgHZp89uks5q3SLlgaJpZM4KeEz7 .

aravantv commented 8 years ago

Ok I understand you can use any other library. But in any case you still need to import xstream don't you?

Widdershin commented 8 years ago

I see what you're saying now, yes, you're right, you could pull in Stream from xstream.

aravantv commented 8 years ago

Sorry was not clear in the first place. Great I'll work on it, but don't expect a pull request before a month or so - going for three weeks on vacation :-)

Widdershin commented 8 years ago

Have a lovely holiday! :smile_cat:

I'll leave this issue unassigned for now, and if you feel like working on it when you get back, just comment and I'll assign it to you.

I'll also open an issue for a typescript rewrite. :smile:

aravantv commented 7 years ago

Hi, for info, I'm back from vacation and working on it! :-)

Widdershin commented 7 years ago

Great to hear. I've been brushing up on my TypeScript recently, looking forward to reviewing :smile:

aravantv commented 7 years ago

Uhhh, I'm myself not an expert... Fearing your reviewing! ;-)

Anyways it's tougher than I thought. I will do it XStream-specific, at least for a start.

On my way I have a collection-specific question: which sort of data is actually carried by a stream issued from Collection? It actually looks like the stream of array of items. But if it was just this, we would not need pluck...?

Widdershin commented 7 years ago

Correct, it is a stream of arrays of item sinks.

You could write an equivalent to pluck like collection$.map(items => xs.combine(...items.map(item => item.property)).flatten() but that doesn't quite work properly if I recall. I think because you need to remember the property stream, but just adding . remember() there isn't good enough because it gets recreated when the collection changes.

Pluck remembers sink streams across collection changes.

Tell you the truth, there's a whole bunch of things that coukd probably be simplified inside of collection, so please keep asking questions as they come up :)