I understand JS lambda functions (mostly when I google JS lambda and JS =>) as below:
const var = (a,b) => { return a*b }
or
const var = (a,b) => a*b
const var = () => a*b
It is easy to explain that we assign value to variable by "calculating" anonymous function with (a,b) parameters or none.
But I was unable to google my question because it was always returning general lambda format as above. My question is how to read this code:
let printJobId = null;
let contentInProgress = false;
async function instantPrint(content) {
await print(
content,
v => (printJobId = v),
v => {
if (v) contentInProgress = content;
else contentInProgress = null;
},
doneResult => finishPrint(doneResult.status)
).then(result => {
notify(result);
});
}
- What exactly line
v => (printJobId = v)does? It seems for me that it assigns v value to printJobId but why the hell we are placing it inside print function call, it doesnt have return value for the v on the left side.
By saying function call I mean functionName(param1, param2) so for me it have no sense at all.
- What exactly those lines does?
v => {
if (v) contentInProgress = content;
else contentInProgress = null;
}
It's similar to the first question. No return from the curly brackets {}. So the v for me looks like it is void and only do some business logic which should not be inside function call as a one of the parameters.
The line
doneResult => finishPrint(doneResult.status)
is easy to understand as finishPrint will return some value so we pass to the print() function, doneResult variable which will have value of the finishPrint return.
I have added also svelte tag as this code might be connected with it, but I believe it is only JS question.
Thank you in advance for all your time!