UNPKG

1.11 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = getAttrsWithChangesRecorder;
7/**
8 * Create a new getAttrs handler who will wrap the original function,
9 * and store the changes internally to be used for other
10 * tools like Analytics later in the code.
11 *
12 * @param getAttrs - Function who gets the new attributes
13 * @return object
14 * @property handler - New handler to get indentation attributes (It wraps the original)
15 * @property getChanges - Return all the stored changes.
16 * @property clear - Clear the changes
17 */
18function getAttrsWithChangesRecorder(getAttrs, options) {
19 var changes = [];
20 function getAttrsWithChangesRecorder(prevAttrs, node) {
21 var newAttrs = getAttrs(prevAttrs, node);
22 changes.push({
23 node: node,
24 prevAttrs: prevAttrs,
25 newAttrs: newAttrs,
26 options: options
27 });
28 return newAttrs;
29 }
30 return {
31 getAttrs: getAttrsWithChangesRecorder,
32 getAndResetAttrsChanges: function getAndResetAttrsChanges() {
33 var oldChanges = changes;
34 changes = [];
35 return oldChanges;
36 }
37 };
38}
\No newline at end of file