botbuilder-dialogs
Version:
A dialog stack based conversation manager for Microsoft BotBuilder.
71 lines • 2.42 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClassMemoryScope = 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");
/**
* ClassMemoryScope maps "class" -> dc.activeDialog.properties
*/
class ClassMemoryScope extends memoryScope_1.MemoryScope {
/**
* Initializes a new instance of the [ClassMemoryScope](xref:botbuilder-dialogs.ClassMemoryScope) class.
*
* @param name Name of the scope class.
*/
constructor(name = scopePath_1.ScopePath.class) {
super(name, false);
}
/**
* Gets the backing memory for this scope.
*
* @param dc The [DialogContext](xref:botbuilder-dialogs.DialogContext) object for this turn.
* @returns The memory for the scope.
*/
getMemory(dc) {
// if active dialog is a container dialog then "dialog" binds to it
if (dc.activeDialog) {
const dialog = this.onFindDialog(dc);
if (dialog != undefined) {
// Clone properties
const clone = {};
for (const key in dialog) {
const prop = dialog[key];
if (Object.prototype.hasOwnProperty.call(dialog, key) && typeof prop != 'function') {
if (isExpression(prop)) {
const { value, error } = prop.tryGetValue(dc.state);
if (!error) {
clone[key] = value;
}
}
else {
clone[key] = prop;
}
}
}
return clone;
}
}
return undefined;
}
/**
* Override to find the dialog instance referenced by the scope.
*
* @param dc Current dialog context.
* @returns The dialog instance referenced by the scope.
*/
onFindDialog(dc) {
return dc.findDialog(dc.activeDialog.id);
}
}
exports.ClassMemoryScope = ClassMemoryScope;
function isExpression(prop) {
return typeof prop == 'object' && typeof prop['tryGetValue'] == 'function';
}
//# sourceMappingURL=classMemoryScope.js.map
;