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

Introduce createServer #467

Merged
merged 1 commit into from
May 19, 2020
Merged

Conversation

dfreeman
Copy link
Contributor

@dfreeman dfreeman commented May 13, 2020

@samselikoff we had a conversation about this a little over a month ago, and I went and implemented it but then never actually committed the files and opened a pull request 🤦

This PR introduces a createServer function as an alternative to writing new Server. While it doesn't add any new functionality, it does have a couple of advantages:

  • It avoids having consumers of the library call a side-effecty constructor (whether that's a code smell or not is a matter of personal opinion, but it's certainly been the topic of lots of angsty blog posts)
  • It allows for type-safe interactions with the server in the context of your config, which was the last lingering topic of discussion in Using mirage of versions above 0.1.35 fails to build and run #396.
    In other words, if I write schema.all('foo') in a route handler, TypeScript can tell based on the foo model/factory I provide what type the result will have. Or, if I haven't provided a foo model, it can correctly flag schema.all('foo') as an error.

/cc @zoltan-nz @chriskrycho

@samselikoff
Copy link
Contributor

Awesome!! Thank you so much for this, I know it will make TS users happy 🙏

@chriskrycho @zoltan-nz any chance y'all could take a quick look or give it a shot in your TS projects?

@zoltan-nz
Copy link
Contributor

@samselikoff Thanks for the heads up.

@dfreeman Brilliant improvement. Love it.

I give it a try today in my project, however it looks good to me already.

@zoltan-nz
Copy link
Contributor

@samselikoff I played with it and works like a charm. Thanks. :)

Copy link
Contributor

@jamescdavis jamescdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 looks good here!

@samselikoff
Copy link
Contributor

Amazing – thanks everyone!

@samselikoff samselikoff merged commit bd0c44a into miragejs:master May 19, 2020
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

Successfully merging this pull request may close these issues.

5 participants