Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript definition #26

Open
aravantv opened this issue Oct 23, 2016 · 12 comments
Open

Typescript definition #26

aravantv opened this issue Oct 23, 2016 · 12 comments
Assignees

Comments

@aravantv
Copy link
Contributor

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
Copy link
Contributor Author

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

@Widdershin
Copy link
Member

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
Copy link
Contributor Author

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

@Widdershin
Copy link
Member

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" [email protected]
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
#26 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAYUHaRKiBJZDPd_74CtrCgsbgHZp89uks5q3SLlgaJpZM4KeEz7
.

@aravantv
Copy link
Contributor Author

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

@Widdershin
Copy link
Member

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

@aravantv
Copy link
Contributor Author

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
Copy link
Member

Have a lovely holiday! 😸

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

@aravantv
Copy link
Contributor Author

aravantv commented Dec 3, 2016

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

@Widdershin
Copy link
Member

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

@aravantv
Copy link
Contributor Author

aravantv commented Dec 3, 2016

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
Copy link
Member

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants