Skip to content

New link architecture - #1366

Merged
KATT merged 77 commits into
nextfrom
katt/observable-new
Jan 20, 2022
Merged

KATT merged 77 commits into
nextfrom
katt/observable-new

Conversation

@KATT

@KATT KATT commented Jan 8, 2022 •

Copy link
Copy Markdown
Member

Breaking change for next major! Full WIP of ideas for next major in #887

New link architecture

What it (hopefully) enables

  • Should enable us to write a @trpc/react-lite-package that doesn't depend on react-query where each feature is composable by a link. This is not the goal in itself, but it's good that the architecture now (should) allow it.
  • Enable better integration with other frameworks that might not have stuff like react-query
  • More power for people using @trpc/client
  • Ability to access response metadata (Access response headers in "vanilla client?" #1353)

Open questions

  • Should the next()-call in a link maybe be called forward() instead to not to confuse with observables' next concept?
  • Should we just use RxJS instead of having our own implementation?
  • Should response errors be errors in the chain? Could be a TRPCResponseError - might work easier with things like retry

Notes from @KATT

  • I'm quite new to observables/RxJS, so keen to get feedback on people who've used it more

Q&A

This is a fat PR - where can I look to get a feel of it?

OK, cool, where's the core juice at that I can review?

Why is it not ES Observable-compliant?

  • I hate this in JS and try to avoid it all cost.
  • If we think this a good idea further on, backwards compatibility should be achievable be added by mapping observable to new Observable()-factory fn

Why not use RxJS/x?

  • I don't want tRPC to have dependencies
  • RxJS is quite heavy
  • RxJS doesn't allow me to specify a generic for Errors

Fuck me, this is a lot, I can't possibly review this

Happy to organize a community call / 1on1 Zoom call for anyone interested in helping out.

@benlesh

benlesh commented Jan 12, 2022

Copy link
Copy Markdown

Hi @KATT! This is very interesting, and I'm very flattered you've been inspired by Rx to take this approach!

That said, I would strongly advise against using a reinvented observable here. Especially if you're exposing it as a public API.

RxJS is:

  • tree-shakable (you only pay for what you use)
  • widely used
  • battle-tested
  • covered by more than 3,000 integration tests
  • covered by hundreds of typescript type/API tests.
  • It's interoperable with many common libraries and supported natively by Angular, Svelte, Vue, and XState, to name a few.

Apollo GraphQL is also looking into moving over to use RxJS for these reasons. Not having dependencies for the sake of not having dependencies may be a mistake here. It's more likely to add weight than remove any, given that the RxJS implementation won't be much larger (if at all), and anyone that is already using RxJS (downloaded 31M times this week) will end up paying the cost of your implementation.

At the very least, if you do decide to go with your own observable implementation, please don't use rx in the name, as it implies it's RxJS, which it is not.

I'm happy to pair with you on this if you'd like.

@KATT

KATT commented Jan 12, 2022

Copy link
Copy Markdown
Member Author

You're making many good points, @benlesh, I'm going to let this marinate a bit.

At the very least, if you do decide to go with your own observable implementation, please don't use rx in the name, as it implies it's RxJS, which it is not.

100% will do.

I'm happy to pair with you on this if you'd like.

Extremely generous offer. I think I can swap them around in a matter of minutes, unless the swap showcases some underlying issues 😅

KATT added 2 commits January 20, 2022 00:15
# Conflicts:
#	packages/react/src/internals/context.tsx
#	yarn.lock
@KATT

KATT commented Jan 20, 2022 •

Copy link
Copy Markdown
Member Author

Will merge this for now and come back to it later. This will be part of next major release which isn't expected for another month or so anyway. #1420

@github-actions

github-actions Bot commented Oct 7, 2022

Copy link
Copy Markdown
Contributor

This pull request has been locked because it had no new activity for 30 days. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

This branch was successfully deployed

3 active deployments
Preview – next-prisma-starter — 643f2830 Deployed Jan 20, 2022 by vercel[bot]
Preview – todomvc — 643f2830 Deployed Jan 20, 2022 by vercel[bot]
Preview – www — 643f2830 Deployed Jan 20, 2022 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

⏭ major bump needed Requires a major version bump 🙏 review please needs community sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants