Developing complex blocks using Window.postMessage() can become a bit messy. One of the main issues is that as a Javascript developer you are most probably using the functional programming paradigm to structure your code, unfortunately, we can't pass functions as arguments using the iframe messages. One work around to maintain some of the functional structure of your code and use a "pass functions as arguments" like behavior is to use the messageMetadata value.

The idea is simple, we store the functions in a matrix and pass a unique identifier in the messageMetadata value to Nitoku main app. On the File manager block, for the deleteFIle method, you can see how we have defined the callbackAfterDeleteFileId value : var callbackAfterDeleteFileId = uniqueID(); and then pass that value to the main Nitoku app on the message.

When then the program receives the response from Nitoku main app we use the unique identifier to run the associated function.

The delete method itself becomes straight forward with to arguments, the uri of the file to be deleted and the success callback function that we want the method to execute after the operation has been successful.