1 | "use strict";
|
2 | var DagGraph_1 = require("../DagGraph");
|
3 | var log = require('debug')('redux-dag-history:DagHistory');
|
4 | function getExistingState(newState, history, config) {
|
5 | if (config.stateKeyGenerator && config.stateEqualityPredicate) {
|
6 | var dagGraph = new DagGraph_1.default(history.graph);
|
7 | var hash = config.stateKeyGenerator(newState);
|
8 | var found = dagGraph.getStateForHash(hash);
|
9 | if (found) {
|
10 | var existingState = new DagGraph_1.default(history.graph)
|
11 | .getState(found);
|
12 | var areEqual = config.stateEqualityPredicate(newState, existingState);
|
13 | if (areEqual) {
|
14 | return found;
|
15 | }
|
16 | log('found hashed state not equal');
|
17 | }
|
18 | else {
|
19 | log('no hashed state found');
|
20 | }
|
21 | }
|
22 | else {
|
23 | log('skip existing state check');
|
24 | }
|
25 | return null;
|
26 | }
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | exports.default = getExistingState;
|