fetch-mock icon indicating copy to clipboard operation
fetch-mock copied to clipboard

Move delay and repeat onto the response object

Open wheresrhys opened this issue 5 years ago • 2 comments

They fit well there. Well, delay definitely does. not sure about repeat

wheresrhys avatar Mar 22 '20 18:03 wheresrhys

I would argue that delay is telling the server (in this case a mocked server) to delay sending the response. The response itself has no control over, or concept of, when it is sent. Same with repeat. We are telling the server how many times to respond to a given route. The response is just an object describing what the server should respond with, and should never be concerned about implementation details at the server level. Especially considering that a raw Response instance is a valid response object, the current implementation makes the most sense, IMO.

chet-manley avatar Apr 13 '20 07:04 chet-manley

The current implementation would still be supported (under the hood the options all get smooshed together anyway), but I see the API more as

  • parameter 1 - decide which requests to respond to
  • parameter 2 - decide how to respond to them -parameter 3 - stuff which feels awkward in both 1 and 2

Another argument for putting delay in 2 is because - until fairly recently - it didn't exist as an option and the only way to delay responses was with either a promise or a function, both of which sit squarely in parameter 2. So delaying responses has historically been a second parameter concern

Thanks for sharing your opinion though - interested to hear it

wheresrhys avatar May 21 '20 20:05 wheresrhys