Files
30-seconds-of-code/node_modules/xstate/lib/mapState.js
2019-08-20 15:52:05 +02:00

36 lines
1.2 KiB
JavaScript

"use strict";
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("./utils");
function mapState(stateMap, stateId) {
var e_1, _a;
var foundStateId;
try {
for (var _b = __values(utils_1.keys(stateMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
var mappedStateId = _c.value;
if (utils_1.matchesState(mappedStateId, stateId) &&
(!foundStateId || stateId.length > foundStateId.length)) {
foundStateId = mappedStateId;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return stateMap[foundStateId];
}
exports.mapState = mapState;
//# sourceMappingURL=mapState.js.map