Giter Site home page Giter Site logo

Comments (4)

leaysgur avatar leaysgur commented on August 16, 2024 1

I prefer Option 3 or 4, for its context is explicit.
But a1ab931 also looks good to me. Since this issue can be handled internally.

Anyway, thank you for quick fix! 🙌🏻

from worktop.

lukeed avatar lukeed commented on August 16, 2024

Ahhh you're right, this is a bug 🙈

I'll put in a temporary fix for now, but this is going to have to be reworked.
What do you think about these options? It'd be for prepare only:

// Option 1:
// Use `true` flag for `prepare` usage
// PRO: Not breaking. Same `compose` utility
// CON: Built-in secondary usage (kinda weird)

API.prepare = compose(
  true, // isPrepare
  CORS.preflight,
  // ... others
);

// no change for route handlers
API.add('GET', '/demo', compose(foo, bar));


// Option 2:
// Change `compose` to (handlers: Handler[], isPrepare?: boolean) signature
// PRO: Clear, single method signature
// CON: Breaking & I find it kinda ugly, lol 

API.prepare = compose([
  CORS.preflight,
  // ... others
], true); //< here

// route handler
API.add('GET', '/demo', compose([foo, bar]));


// Option 3:
// Add new `group` utility *only* for prepare usage
// PRO: Not breaking
// CON: Choosing between group vs compose may be confusing

API.prepare = group(
  CORS.preflight,
  // ... others
)

// no changes to route handlers
API.add('GET', '/demo', compose(foo, bar));


// Option 4:
// Make `prepare` accept Array of handler
// PRO: Not breaking, no `compose` confusion
// CON: Doesn't feel very nice (personal?)

API.prepare = [
  CORS.preflight,
  // ... others
]

// no changes to route handlers
API.add('GET', '/demo', compose(foo, bar));

from worktop.

lukeed avatar lukeed commented on August 16, 2024

I actually did this in a way that should be fine when subrouters (#29) land too.
It's not super-duper ideal, but it works 😅

from worktop.

lukeed avatar lukeed commented on August 16, 2024

Thanks for the feedback (and the report!)

It might not need to change at all going forward, luckily.

from worktop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.