Skip to content

Instantly share code, notes, and snippets.

@Restuta
Last active January 12, 2019 01:21
Show Gist options
  • Save Restuta/09058d6f4aca96820a918e541ed29662 to your computer and use it in GitHub Desktop.
Save Restuta/09058d6f4aca96820a918e541ed29662 to your computer and use it in GitHub Desktop.
Collect Audit Log Updates
// 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