Replies: 4 comments
-
@benlesh Is this any good? 🤔😅 |
Beta Was this translation helpful? Give feedback.
-
I think this is really cool. I'm not sure I agree with all of the design choices, but I like the spirit of it. If we did have a design we agreed on, we'd need to have a migration plan. How do we get millions of users there gracefully over a series of major releases? What does the deprecation track look like? Are there code transformations we can do? Etc. RxJS is unfortunately way too popular to make big, breaking changes to API design without careful considerations like that. |
Beta Was this translation helpful? Give feedback.
-
I'm so happy that you find it cool! :D And I really appreciate that you asked these questions instead of just dismissing the proposal. I think we can at least agree upon the fact that if we want type-safety Let's say we have an emitter Now imagine someone wrote The point I want to make is As a matter of fact I started working on type-safety keeping the API same but when I realised fromEvent also takes array of emitters then things became a little too much. That is when I thought let me roll my own fromEvent-like thing. And beyond all this what I like about Regarding other design disagreements, if you can be specific we can come to a common ground. Regarding migration, // 01 ---
// before:
fromEvent(emitter, name);
// after:
fromEmitter(emitter).event(name);
// 02 ---
// before:
fromEvent<T>(emitter, name);
// after:
fromEmitter(emitter).event(name) as Observable<T>;
// 03 ---
// before:
fromEvent(emitter, name, options);
// after:
fromEmitter(emitter).event(name, options);
// 04 ---
// before:
fromEvent<T>(emitter, name, options);
// after:
fromEmitter(emitter).event(name, options) as Observable<T>;
// 05 ---
// before:
fromEvent(arrayOfEmitters, name);
// after:
merge(...
arrayOfEmitters
.map(e => fromEmitter(e).event(name))
);
// 06 ---
// before:
fromEvent<T>(arrayOfEmitters, name);
// after:
merge(...
arrayOfEmitters
.map(e => fromEmitter(e).event(name))
) as Observable<T>;
// 07 ---
// before:
fromEvent(arrayOfEmitters, name, options);
// after:
merge(...
arrayOfEmitters
.map(e => fromEmitter(e).event(name, options))
);
// 08 ---
// before:
fromEvent<T>(arrayOfEmitters, name, options);
// after:
merge(...
arrayOfEmitters
.map(e => fromEmitter(e).event(name, options))
) as Observable<T>;
// 09 ---
// before:
fromEvent(arrayLikeOfEmitters, name);
// after:
merge(...
[...arrayLikeOfEmitters]
.map(e => fromEmitter(e).event(name))
);
// 10 ---
// before:
fromEvent<T>(arrayLikeOfEmitters, name);
// after:
merge(...
[...arrayLikeOfEmitters]
.map(e => fromEmitter(e).event(name))
) as Observable<T>;
// 11 ---
// before:
fromEvent(arrayLikeOfEmitters, name, options);
// after:
merge(...
[...arrayLikeOfEmitters]
.map(e => fromEmitter(e).event(name, options))
);
// 12 ---
// before:
fromEvent<T>(arrayLikeOfEmitters, name, options);
// after:
merge(...
[...arrayLikeOfEmitters]
.map(e => fromEmitter(e).event(name, options))
) as Observable<T>; This assumes that users are using In most cases users can and should remove const assertType =
<T>() =>
($: Observable<unknown>) =>
$ as Observable<T> Also if the I don't know how difficult it will be to make code transformers but I have a feeling it shouldn't be much hard in case of TypeScript. In case of JavaScript I guess we can't really tell if it's a single emitter or array of emitters with 100% accuracy. Also this refactoring will require spread version of So first step now is to agree upon the design and API. If the current design is good, I can explore writing code transformers. |
Beta Was this translation helpful? Give feedback.
-
Did this ever lead to a change in RxJS? Because I can't see it, but I also haven't seen anyone argue for why not to implement this in RxJS. Well I did see some argument that RxJS is supposed to work both in browsers (using the types from the dom library) and in node (using the types from node) and they argued that it was impossible for make it work for both, without forcing the developer using this function to have to import one of those TS type definition libraries when they don't need them. Is that the reason this never worked out? When I read that argument I was wondering whether it might be possible to define in I honestly am just making stuff up here. I don't actually know whether something like that could be possible. But it seems like a feature that could exist, or something like it? Or that we could request to have implemented in a future version of Node and / or Typescript? |
Beta Was this translation helpful? Give feedback.
-
TLDR: I have implemented a
fromEvent
alternative that is type-safe and has some additional features. And I want to know if I can open a PR. :)So, as you people might know
fromEvent
's types are not really great which is fair considering when they were written it wasn't possible to statically type it. But now we can have better types forfromEvent
.So in this light, I implemented rxjs-from-emitter. I recommend checking out the readme to see all it's features, but in short these are it's two major features -
Observable
inferences corresponding to listener's arguments.If this implementation is in alignment with RxJS's goals and interests, I would be more than happy to send a PR :) I have answers to all your questions. Also don't get distracted with the change in API, it's the types that are important. To put it in the perspective runtime code is ~100 LOC where as type-level code is ~600 LOC.
Also additional to the type-safety, according to me there are some (respectfully) design-level flaws of
fromEvent
that rxjs-from-emitter solves which I have documented here.PS: In case this comes across a publicity stunt to promote my package or whatever, it's not. I love RxJS and I genuinely want to make it better :)
Also I will take this opportunity to thank everyone that constantly works on RxJS to make it better!
Beta Was this translation helpful? Give feedback.
All reactions