What style of passing properties you would prefer when calling a function that destructures an object parameter. The function being invoked has the signature
function constructDebugLog({
currentOS,
originalUserStashState,
userAgent,
}) { ...
Which way of invoking the function is more sensible
const { currentOS, originalUserStashState, userAgent } = store.getState()
constructDebugLog({ currentOS, originalUserStashState, userAgent })
.then(resolve)
.catch(reject)
constructDebugLog(store.getState())
.then(resolve)
.catch(reject)
Calling getState()
provides a complex object, but since the receiving function destructures it, is there even a need to explicate as done in #1?
I think the main difference here is the authors intent:
1) You want to pass some losely related properties to a function, that they are all from the same datasource is a coincidence.
2) You pass the state around. That the function destructures it means that it only access certain properties of the state, but the author assumed that a state object would be passed.
In this case I think the later applies, and then I'd go with that version (it also makes the code slightly more readable IMO).
Concerning "performance" and "best practice":
Do you have a problem with performance? If no, why do you bother? If yes, these two lines are not the cause of it.
And "best practice" is always opinionated, I'd consider both versions as valid.