fastify / fastify-dx

Archived
900 stars 42 forks source link

Revise URMA Rendering Options #24

Open reconbot opened 2 years ago

reconbot commented 2 years ago

Prerequisites

🚀 Feature Proposal

I was reading the rendering options and was wondering if they were exclusive of eachother? And if so maybe they should be a string union or enum?

Motivation

Prevents impossible states from happening.

Example

interface RouteModule {
  renderingMode?: 'server' | 'client' | 'isomorphic' // default is isomophic
  streaming?: boolean
  generated?: boolean // I noticed this wasn't documented
}
galvez commented 2 years ago

Hey there! Yeah, I thought about using an enum but I feel setting flags to booleans is more developer friendly than assigning strings to a single property? Maybe it's just me, just a perception — but it might be the case that we have a mode property as an alternative to the boolean flags? WDYT?

galvez commented 2 years ago

The generated flag is for SSG, which I'm adding support for in the next cycle.

reconbot commented 2 years ago

I think with typescript or js with an editor that understands types it's really easy to autocomplete the strings and typecheck if you make a typo etc.

I think having both is a bad idea for the same reasons having having multiple booleans that represent the same thing is a bad idea. It's possible to represent a bad state even if you typecheck.

I was on the fence if "streaming" is part of "renderingMode" because I'm not sure if "streaming" is relevant for client side rendering or not. (I think it is or could be one day?)

galvez commented 2 years ago

You do make a compelling argument, sir. I'm tempted to make this change for 0.3 onwards.

dac09 commented 2 years ago

+1 on this. I came here to say exactly the same. It's also much easier to reason at a glance how a route would be rendered!