What is the point of using the spread operator as parameter inreturn withDefaultStatus(...)
?
I've been staring and poking at this code for a while now and i can't figure something out.
At first i thought it's used as a condition, but now i'm totally confused.
PS1: I don't think it has anything to do with lodash, but i added it anyway.
PS2: The state is being passed from a React Component.
const {defaults} = require('lodash/fp')
const withDefaultStatus = defaults({
isFinished: false,
isPending: true,
code: 0
});
const state = {
isFinished: true,
isMutation: false,
isPending: false,
lastUpdated: 1512730452993,
queryCount: 5,
status: 1,
url: "https://",
}
function selectQueryStatus(state) {
const {
isFinished,
isPending,
status: code,
lastUpdated,
queryCount
} = state || {};
return withDefaultStatus({
isFinished, isPending , ...code && { code, lastUpdated, queryCount }
});
}
console.log(selectQueryStatus(state))
//output { isFinished: true, isPending: false, code: 1, lastUpdated: 512730452993, queryCount: 5 }