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

Change lolex.install signature #103

Merged
merged 2 commits into from
Jul 13, 2017

Conversation

fatso83
Copy link
Contributor

@fatso83 fatso83 commented Jun 29, 2017

As shown in #102, something as simple as adding one additional configuration option becomes unmanageable due to the current design of a "telescoping method signature" where all the arguments are optional. This makes contributors reach for alternate ways of configuring lolex, such as adding flags on the object.

I propose we change the signature to accept a single configuration object with named parameters to simplify this. This PR is that proposal implemented. There are also many other pros to constructor-like functions like this of 1-arity.

This is a breaking change and will require a new major version.

@acud
Copy link
Contributor

acud commented Jun 30, 2017

I think that leaving the possibility for
lolex.install("2015-01-01")
OR
lolex.install(epochValue OR Date object)
should still be maintained. the changes would and should break anything above 1 parameter to the install function but maybe the support for different default initialisations should be kept?

@fatso83
Copy link
Contributor Author

fatso83 commented Jun 30, 2017

I see your point, but I dunno ... IMHO if we break the signature, we might as well make it consistently break, not just surprisingly break for some of the combinations.

@fatso83
Copy link
Contributor Author

fatso83 commented Jul 11, 2017

@mroderick do you have any input on this? there was a sudden influx of changes, and so I thought this might be a good time to add this before accepting some of them.

/**
* @param config {Object} optional config
* @param config.target {Object} the target to install timers in (default `window`)
* @param config.now {number|Date} a number (in milliseconds) or a Date object (default epoch)
Copy link
Member

Choose a reason for hiding this comment

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

Is this parameter optional? Should it have a default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the current parameters are optional, lolex.install() is used in the README, so this behaviour-preserving and should not break anything.

We could add more explicit defaults of course, before sending them on to createClock and such (that have their own defaults), but I felt that would perhaps obfuscate my intent in this PR. Could add that in another commit, of course.

Copy link
Member

Choose a reason for hiding this comment

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

Faking time is confusing enough as it is, let's not change the api too much :)

var clock = createClock(now, loopLimit);
var i, l;
var target = config.target || global;
var clock = createClock(config.now, config.loopLimit);
Copy link
Member

Choose a reason for hiding this comment

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

What happens if config.now is undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same as today. It is converted to 0 down the line.

I am not a super-fan of the current digging-down-into-the-code to see if not passing a number is allowed or not, so adding defaults higher up along with strict checking further down, is more my style.

@mroderick
Copy link
Member

:shipit:

@fatso83
Copy link
Contributor Author

fatso83 commented Jul 12, 2017

Not totally sure what the squirrel with hat means ... Is that an approval? 😂

@mroderick
Copy link
Member

@mroderick
Copy link
Member

I am happy with this PR, merge it!

@fatso83 fatso83 merged commit d0b5dae into sinonjs:master Jul 13, 2017
@fatso83 fatso83 deleted the change-install-signature branch July 13, 2017 08:42
yfdyh000 added a commit to yfdyh000/SwitchyOmega that referenced this pull request Jan 26, 2019
update lolex.install: sinonjs/fake-timers#103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants