Last active
January 12, 2019 01:21
-
-
Save Restuta/09058d6f4aca96820a918e541ed29662 to your computer and use it in GitHub Desktop.
Collect Audit Log Updates
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
// prototype of a pattern that allows to collect certain objects/operations | |
// during function exectution | |
const createContainer = (items = []) => ({ | |
getAll: () => items, | |
add: x => items.push(x), | |
}); | |
const applyUpdates = ({ onNewAuditLogRecord }) => x => { | |
onNewAuditLogRecord(x); | |
}; | |
const auditLogRecords = createContainer(); | |
const applyUpdatesWithAuditLog = applyUpdates({ | |
onNewAuditLogRecord: record => auditLogRecords.add(record), | |
}); | |
applyUpdatesWithAuditLog(9); | |
applyUpdatesWithAuditLog(99); | |
applyUpdatesWithAuditLog(990); | |
auditLogRecords.getAll(); //? [9, 99, 990] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment