Repository URL to install this package:
|
Version:
1.1.21 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.stateTreeIdentifier = stateTreeIdentifier;
exports.default = void 0;
var _index = require("../chain-able/index.js");
var _IDENTIFIER_REGISTRY = require("./IDENTIFIER_REGISTRY");
var _uuid = require("./uuid");
// eslint-disable-next-line
function concatIdentifier(obj) {
let identifier = '';
if (obj.userid) {
identifier += obj.userid;
} else if (obj.orderid) {
identifier += obj.orderid;
} else if (obj.identifier) {
identifier += obj.identifier;
} else if (obj.cardid) {
identifier += obj.cardid;
} else if (obj.itemid) {
identifier += obj.itemid;
} else if (obj.skuid) {
identifier += obj.skuid;
} else if (obj.addressid) {
identifier += obj.addressid;
} else if (obj.id) {
identifier += obj.id;
}
return identifier;
} // eslint-disable-next-line
function stateTreeIdentifier(obj = {}, old) {
if (obj.__identifier) {
return obj.__identifier;
}
const identifier = concatIdentifier(old || obj);
if (identifier !== '') {
return identifier;
}
if (_IDENTIFIER_REGISTRY.IDENTIFIER_STRING_REGISTRY.has(obj)) {
return _IDENTIFIER_REGISTRY.IDENTIFIER_STRING_REGISTRY.get(obj);
}
const string = (0, _index.stringify)(obj);
if (_IDENTIFIER_REGISTRY.IDENTIFIER_REFERENCE_REGISTRY.has(string)) {
return _IDENTIFIER_REGISTRY.IDENTIFIER_REFERENCE_REGISTRY.get(string);
}
const unique = (0, _uuid.uuid)() + string;
const hashstring = '__' + (0, _index.fliphash)(unique);
_IDENTIFIER_REGISTRY.IDENTIFIER_REFERENCE_REGISTRY.set(string, hashstring);
_IDENTIFIER_REGISTRY.IDENTIFIER_STRING_REGISTRY.set(obj, hashstring);
return hashstring;
}
var _default = stateTreeIdentifier;
exports.default = _default;