PromptsState.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. *
  6. * (C) Copyright IBM Corp. 2019, 2020
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure
  9. * restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define([], function () {
  12. var MAX_CALL_COUNT = 3;
  13. /**
  14. * Class to keep prompts state. The owner of this class is a widget since prompt values are cached at widget level.
  15. */
  16. var PromptsState = function () {
  17. function PromptsState() {
  18. _classCallCheck(this, PromptsState);
  19. this._promptsState = {};
  20. }
  21. PromptsState.prototype.destroy = function destroy() {
  22. this._promptsState = null;
  23. };
  24. PromptsState.prototype.reset = function reset() {
  25. this._promptsState = {};
  26. };
  27. /**
  28. * @param {PromptSpec[]} specList Array of the prompt specs
  29. */
  30. PromptsState.prototype.updatePromptsState = function updatePromptsState(specList) {
  31. var _this = this;
  32. specList && specList.forEach(function (spec) {
  33. // Increase the call count for each prompt
  34. var state = _this._promptsState[spec.name];
  35. if (!state) {
  36. _this._promptsState[spec.name] = 0;
  37. }
  38. _this._promptsState[spec.name]++;
  39. });
  40. };
  41. PromptsState.prototype.hasInProgressPrompts = function hasInProgressPrompts() {
  42. return Object.keys(this._promptsState).length > 0;
  43. };
  44. PromptsState.prototype.hasInValidState = function hasInValidState(specList) {
  45. var _this2 = this;
  46. // Is invalid if specList is undefined or at least one prompt tries to resolve the prompt values more than MAX_CALL_COUNT
  47. return !specList || specList.find(function (spec) {
  48. return _this2._promptsState[spec.name] && _this2._promptsState[spec.name] >= MAX_CALL_COUNT;
  49. }) !== undefined;
  50. };
  51. return PromptsState;
  52. }();
  53. return PromptsState;
  54. });
  55. //# sourceMappingURL=PromptsState.js.map