UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

125 lines 4.52 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import { ExperiencePerformanceTypes, ExperienceTypes, UFOExperience } from '@atlaskit/ufo'; export var experienceConfig = { type: ExperienceTypes.Operation, performanceType: ExperiencePerformanceTypes.Custom, platform: { component: 'editor' } }; export var EditorExperience = /*#__PURE__*/function (EditorExperience) { EditorExperience["loadEditor"] = "load"; EditorExperience["typing"] = "type"; EditorExperience["interaction"] = "interact"; EditorExperience["editSession"] = "edit-session"; return EditorExperience; }({}); export var RELIABILITY_INTERVAL = 30000; export var ExperienceStore = /*#__PURE__*/function () { function ExperienceStore() { _classCallCheck(this, ExperienceStore); this.experiences = new Map(); for (var _i = 0, _Object$values = Object.values(EditorExperience); _i < _Object$values.length; _i++) { var experienceId = _Object$values[_i]; var experience = new UFOExperience(experienceId, experienceConfig); this.experiences.set(experienceId, experience); } } _createClass(ExperienceStore, [{ key: "get", value: function get(experienceId) { return this.experiences.get(experienceId); } }, { key: "getActive", value: function getActive(experienceId) { var experience = this.experiences.get(experienceId); if (!(experience !== null && experience !== void 0 && experience.state.final)) { return experience; } } }, { key: "getAll", value: function getAll() { return Array.from(this.experiences.values()); } }, { key: "start", value: function start(experienceId, startTime) { var _this$get; (_this$get = this.get(experienceId)) === null || _this$get === void 0 || _this$get.start(startTime); } }, { key: "addMetadata", value: function addMetadata(experienceId, metadata) { var _this$get2; (_this$get2 = this.get(experienceId)) === null || _this$get2 === void 0 || _this$get2.addMetadata(metadata); } }, { key: "mark", value: function mark(experienceId, _mark, value) { var _this$get3; (_this$get3 = this.get(experienceId)) === null || _this$get3 === void 0 || _this$get3.mark(_mark, value); } }, { key: "success", value: function success(experienceId, metadata) { var _this$getActive; return (_this$getActive = this.getActive(experienceId)) === null || _this$getActive === void 0 ? void 0 : _this$getActive.success({ metadata: metadata }); } }, { key: "fail", value: function fail(experienceId, metadata) { var _this$getActive2; (_this$getActive2 = this.getActive(experienceId)) === null || _this$getActive2 === void 0 || _this$getActive2.failure({ metadata: metadata }); } }, { key: "abort", value: function abort(experienceId, metadata) { var _this = this; // We add this wait in here because when React catches an error it unmounts the component // before the error boundary's componentDidCatch is called // In this case we want to fail the experience, but without this wait, abort is called first setTimeout(function () { var _this$getActive3; (_this$getActive3 = _this.getActive(experienceId)) === null || _this$getActive3 === void 0 || _this$getActive3.abort({ metadata: metadata }); }, 0); } }, { key: "abortAll", value: function abortAll(metadata) { var _this2 = this; this.experiences.forEach(function (experience) { _this2.abort(experience.id, metadata); }); } }, { key: "failAll", value: function failAll(metadata) { var _this3 = this; this.experiences.forEach(function (experience) { _this3.fail(experience.id, metadata); }); } }], [{ key: "getInstance", value: function getInstance(view) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; if (!this.stores.get(view) || options !== null && options !== void 0 && options.forceNewInstance) { var store = new ExperienceStore(); this.stores.set(view, store); } return this.stores.get(view); } }]); return ExperienceStore; }(); _defineProperty(ExperienceStore, "stores", new WeakMap());