I am confused by the following code.
Sourceexport const createProject = (project) => {
return (dispatch, getState, {getFirestore}) => {
// make async call to database
const firestore = getFirestore();
firestore.collection('projects').add({
...project,
authorFirstName: 'Net',
authorLastName: 'Ninja',
authorId: 12345,
createdAt: new Date()
}).then(() => {
dispatch({ type: 'CREATE_PROJECT_SUCCESS' });
}).catch(err => {
dispatch({ type: 'CREATE_PROJECT_ERROR' }, err);
});
}
};
My question is about this line.
return (dispatch, getState, {getFirestore}) => {...
What makes this work? Where do the arguments come from? What calls them? Aren't all these arguments already in scope? Why do we need createProject to return a second function? Is createProject returning a second function? Or is it immediately invoking an inline function? What triggers the return function to run?
I'm just generally very confused by this pattern. Can someone please break it down for me?