var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { LogClass } from './utils.js';
/**
 * This recorder will
 * - store auto-snapshots (afterDispatch) in memory after every dispatch (for time traveling)
 * - store manual snapshots in memory
 *
 * @category Machine
 */
let MemoryRecorder = class MemoryRecorder {
    constructor() {
        this.autoSnaps = [];
        this.manualSnaps = [];
    }
    async afterDispatch(snapshot) {
        this.autoSnaps.push(snapshot);
    }
    async getSnapshots() {
        return this.autoSnaps;
    }
    async createSnapshot(snapshot) {
        // We push them to a different array so we don't interfere with any timetraveling sequence in the autoSnap array
        this.manualSnaps.push(snapshot);
    }
    async loadSnapshot(id) {
        if (id) {
            return (this.autoSnaps.find((s) => { var _a; return ((_a = s.action) === null || _a === void 0 ? void 0 : _a.id) === id; }) || this.manualSnaps.find((s) => { var _a; return ((_a = s.action) === null || _a === void 0 ? void 0 : _a.id) === id; }) || null);
        }
        return this.autoSnaps[this.autoSnaps.length - 1] || this.manualSnaps[this.manualSnaps.length - 1] || null;
    }
};
MemoryRecorder = __decorate([
    LogClass()
], MemoryRecorder);
export { MemoryRecorder };
//# sourceMappingURL=MemoryRecorder.js.map