botbuilder-dialogs
Version:
A dialog stack based conversation manager for Microsoft BotBuilder.
55 lines • 1.71 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.TurnMemoryScope = void 0;
/**
* @module botbuilder-dialogs
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const memoryScope_1 = require("./memoryScope");
const scopePath_1 = require("../scopePath");
/**
* @private
*/
const TURN_STATE = 'turn';
/**
* TurnMemoryScope represents memory scoped to the current turn.
*/
class TurnMemoryScope extends memoryScope_1.MemoryScope {
/**
* Initializes a new instance of the [TurnMemoryScope](xref:botbuilder-dialogs.TurnMemoryScope) class.
*/
constructor() {
super(scopePath_1.ScopePath.turn, true);
}
/**
* Get the backing memory for this scope.
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for this turn.
* @returns The memory for the scope.
*/
getMemory(dc) {
let memory = dc.context.turnState.get(TURN_STATE);
if (typeof memory != 'object') {
memory = {};
dc.context.turnState.set(TURN_STATE, memory);
}
return memory;
}
/**
* Changes the backing object for the memory scope.
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) for this turn.
* @param memory Memory object to set for the scope.
*/
setMemory(dc, memory) {
if (memory == undefined) {
throw new Error('TurnMemoryScope.setMemory: undefined memory object passed in.');
}
dc.context.turnState.set(TURN_STATE, memory);
}
}
exports.TurnMemoryScope = TurnMemoryScope;
//# sourceMappingURL=turnMemoryScope.js.map
;