This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
simply, a thunk is a function that returns a function. in our case, thunk middleware holds a ref to the store, namely dispatch and getState. this occurs at the time you create your store and pass applyMiddleware as arg. | |
now, whenever you dispatch an action, thunk will intercept this function, attach dispatch and getState, providing us the ability to dispatch n times and have access to the store state. powerful stuff. | |
let's take a look at some code: | |
function createThunkMiddleware(extraArgument) { | |
return function (_ref) { | |
var dispatch = _ref.dispatch, | |
getState = _ref.getState; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mainThread = initMainThread(); | |
mainThread.processScript() | |
while (mainThread.processing) { | |
if (work) callStack.push(work) | |
} | |
const callStack = () => { | |
while (callStack.executing()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As a client side developer, it is commonplace to need to parse and structure payloads in order to consume and display properly | |
within the UI. Some considerations during this process: | |
* Is the data we are after always present? Perhaps some objects in payload do not contain field | |
* What is the average payload size? The larger it is, a more efficient algorithmic procedure is required | |
In my current project, we are often faced with massive payloads that could, quite literally, have an infinite amount of nested | |
fields. | |
For context, I needed the ID of every category a user has created. A category can contain three sublevels | |
e.g. |