1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _MapStorage = require("./MapStorage");
|
8 |
|
9 | var _MapStorage2 = _interopRequireDefault(_MapStorage);
|
10 |
|
11 | var _SessionStorage = require("./SessionStorage");
|
12 |
|
13 | var _SessionStorage2 = _interopRequireDefault(_SessionStorage);
|
14 |
|
15 | var _Storage = require("./Storage");
|
16 |
|
17 | var _Storage2 = _interopRequireDefault(_Storage);
|
18 |
|
19 | var _CacheEntry = require("../cache/CacheEntry");
|
20 |
|
21 | var _CacheEntry2 = _interopRequireDefault(_CacheEntry);
|
22 |
|
23 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | class SessionMapStorage extends _Storage2.default {
|
31 | static get $dependencies() {
|
32 | return [_MapStorage2.default, _SessionStorage2.default];
|
33 | }
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | constructor(map, session) {
|
43 | super();
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | this._map = map;
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | this._session = session;
|
58 | }
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 | init() {
|
65 | this._map.clear();
|
66 |
|
67 | for (let key of this._session.keys()) {
|
68 | this._map.set(key, this._session[key]);
|
69 | }
|
70 |
|
71 | return this;
|
72 | }
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 | has(key) {
|
79 | return this._map.has(key);
|
80 | }
|
81 | |
82 |
|
83 |
|
84 |
|
85 |
|
86 | get(key) {
|
87 | return this._map.get(key);
|
88 | }
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 | set(key, value) {
|
95 | let canBeSerializedToJSON = !(value instanceof Promise) && (!(value instanceof _CacheEntry2.default) || !(value.getValue() instanceof Promise));
|
96 |
|
97 | if (canBeSerializedToJSON) {
|
98 | this._session.set(key, value);
|
99 | }
|
100 |
|
101 | this._map.set(key, value);
|
102 |
|
103 | return this;
|
104 | }
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 | delete(key) {
|
111 | this._session.delete(key);
|
112 |
|
113 | this._map.delete(key);
|
114 |
|
115 | return this;
|
116 | }
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 | clear() {
|
123 | this._session.clear();
|
124 |
|
125 | this._map.clear();
|
126 |
|
127 | return this;
|
128 | }
|
129 | |
130 |
|
131 |
|
132 |
|
133 |
|
134 | keys() {
|
135 | return this._map.keys();
|
136 | }
|
137 | |
138 |
|
139 |
|
140 |
|
141 |
|
142 | size() {
|
143 | return this._map.size();
|
144 | }
|
145 |
|
146 | }
|
147 |
|
148 | exports.default = SessionMapStorage;
|
149 |
|
150 | typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/storage/SessionMapStorage', [], function (_export, _context) {
|
151 | 'use strict';
|
152 | return {
|
153 | setters: [],
|
154 | execute: function () {
|
155 | _export('default', exports.default);
|
156 | }
|
157 | };
|
158 | });
|