@threekit-tools/treble 0.0.59 → 0.0.60-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.setConfiguration = exports.getHydratedAttributes = exports.getAttributes = exports.setAttributes = void 0;
39
+ exports.setConfiguration = exports.getHydrationData = exports.getAttributes = exports.setAttributes = void 0;
40
40
  var toolkit_1 = require("@reduxjs/toolkit");
41
41
  var treble_1 = require("./treble");
42
42
  var translations_1 = require("./translations");
@@ -79,55 +79,8 @@ var reducer = (0, toolkit_1.createSlice)({
79
79
  ****************************************************/
80
80
  var getAttributes = function (state) { return state.attributes; };
81
81
  exports.getAttributes = getAttributes;
82
- exports.getHydratedAttributes = (0, toolkit_1.createSelector)(exports.getAttributes, translations_1.getTranslations, translations_1.getLanguage, function (attributes, translations, language) {
83
- var hasTranslation = !!language && !!translations;
84
- return Object.values(attributes).reduce(function (output, attribute) {
85
- var _a;
86
- var _b;
87
- return Object.assign(output, (_a = {},
88
- _a[attribute.name] = Object.assign({}, attribute, {
89
- label: hasTranslation
90
- ? ((_b = translations === null || translations === void 0 ? void 0 : translations[attribute.name]) === null || _b === void 0 ? void 0 : _b[language]) || attribute.name
91
- : attribute.name,
92
- }, attribute.type === 'String'
93
- ? {
94
- values: attribute.values.map(function (el) {
95
- var _a;
96
- return Object.assign({}, el, {
97
- label: hasTranslation
98
- ? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.label]) === null || _a === void 0 ? void 0 : _a[language]) || el.label
99
- : el.label,
100
- handleSelect: function () {
101
- var _a;
102
- return window.threekit.configurator.setConfiguration((_a = {},
103
- _a[attribute.name] = el.value,
104
- _a));
105
- },
106
- selected: attribute.value === el.value,
107
- });
108
- }),
109
- }
110
- : attribute.type === 'Asset'
111
- ? {
112
- values: attribute.values.map(function (el) {
113
- var _a;
114
- return Object.assign({}, el, {
115
- label: hasTranslation
116
- ? ((_a = translations === null || translations === void 0 ? void 0 : translations[el.name]) === null || _a === void 0 ? void 0 : _a[language]) || el.name
117
- : el.name,
118
- handleSelect: function () {
119
- var _a;
120
- return window.threekit.configurator.setConfiguration((_a = {},
121
- _a[attribute.name] = el.assetId,
122
- _a));
123
- },
124
- selected: attribute.value.assetId === el.assetId,
125
- });
126
- }),
127
- }
128
- : undefined),
129
- _a));
130
- }, {});
82
+ exports.getHydrationData = (0, toolkit_1.createSelector)(exports.getAttributes, translations_1.getLanguage, function (attributes, language) {
83
+ return [attributes, translations_1.TRANSLATIONS, language];
131
84
  });
132
85
  // Configurator
133
86
  var setConfiguration = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
@@ -1,58 +1,67 @@
1
1
  import { RootState, ThreekitDispatch } from './index';
2
- import { IMetadata, IConfiguration, IProducts } from '../threekit';
2
+ import { IMetadata, IConfiguration, IProduct } from '../threekit';
3
3
  import { IConnectionConfig } from '../connection';
4
4
  import { IReloadConfig } from './treble';
5
5
  /*****************************************************
6
6
  * Types and Interfaces
7
7
  ****************************************************/
8
8
  export interface CachedProduct {
9
+ id: undefined | string;
9
10
  name?: string;
10
11
  label?: string;
11
12
  thumbnail?: string;
12
13
  connection: IConnectionConfig;
13
14
  configuration: IConfiguration;
14
15
  }
15
- export interface CachedProductState extends Pick<CachedProduct, 'name' | 'label' | 'thumbnail'> {
16
+ export interface CachedProductState extends Pick<CachedProduct, 'id' | 'name' | 'label' | 'thumbnail'> {
16
17
  data: string;
17
18
  }
19
+ interface IEnvConfig extends Record<string, Partial<IProduct>> {
20
+ }
21
+ export interface IHydratedProducts extends Record<string, IEnvConfig> {
22
+ }
18
23
  export interface ProductState {
24
+ id: undefined | string;
19
25
  name: undefined | string;
20
26
  metadata: undefined | IMetadata;
21
- cachedProducts: Array<CachedProductState>;
22
- activeProductIdx: number;
27
+ cache: Array<CachedProductState>;
28
+ activeCacheIdx: number;
23
29
  }
24
30
  /*****************************************************
25
31
  * Constants
26
32
  ****************************************************/
27
- export declare let PRODUCTS: IProducts;
33
+ export declare let PRODUCTS: IHydratedProducts;
28
34
  /*****************************************************
29
35
  * Actions
30
36
  ****************************************************/
37
+ export declare const setProductId: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<string | undefined, string>;
31
38
  export declare const setName: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
32
39
  export declare const setMetadata: import("@reduxjs/toolkit").ActionCreatorWithPayload<IMetadata, string>;
33
- export declare const addProductToCache: import("@reduxjs/toolkit").ActionCreatorWithPayload<CachedProductState, string>;
40
+ export declare const appendToCache: import("@reduxjs/toolkit").ActionCreatorWithPayload<CachedProductState, string>;
34
41
  export declare const updateActiveProductCache: import("@reduxjs/toolkit").ActionCreatorWithPayload<CachedProductState, string>;
35
- export declare const removeProductFromCache: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, string>;
36
- export declare const setActiveProductIdx: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, string>;
37
- export declare const incrementActiveProductIdx: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<undefined, string>;
38
- export declare const decrementActiveProductIdx: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<undefined, string>;
42
+ export declare const removeFromCache: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, string>;
43
+ export declare const setActiveCacheIdx: import("@reduxjs/toolkit").ActionCreatorWithPayload<number, string>;
44
+ export declare const incrementActiveCacheIdx: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<undefined, string>;
45
+ export declare const decrementActiveCacheIdx: import("@reduxjs/toolkit").ActionCreatorWithOptionalPayload<undefined, string>;
39
46
  declare const reducer: import("redux").Reducer<ProductState, import("redux").AnyAction>;
40
47
  /*****************************************************
41
48
  * Standard Selectors
42
49
  ****************************************************/
50
+ export declare const getProductId: (state: RootState) => undefined | string;
43
51
  export declare const getName: (state: RootState) => undefined | string;
44
52
  export declare const getMetadata: (state: RootState) => undefined | IMetadata;
45
- export declare const getActiveProductIdx: (state: RootState) => number;
53
+ export declare const getActiveCacheIdx: (state: RootState) => number;
46
54
  export declare const getProductCache: (state: RootState) => Array<Pick<CachedProduct, 'name' | 'label' | 'thumbnail'>>;
47
55
  /*****************************************************
48
56
  * Complex Actions
49
57
  ****************************************************/
50
- export declare const initProduct: (prods?: IProducts | undefined) => (dispatch: ThreekitDispatch, getState: () => RootState) => void;
58
+ export declare const initProduct: (prods?: IHydratedProducts | undefined) => (dispatch: ThreekitDispatch, getState: () => RootState) => void;
51
59
  export declare const cacheActiveProduct: (config?: Pick<IReloadConfig, "label" | "thumbnail"> | undefined) => (dispatch: ThreekitDispatch, getState: () => RootState) => {
52
60
  payload: CachedProductState;
53
61
  type: string;
54
62
  };
63
+ export declare const loadProduct: (id: string) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
55
64
  export declare const loadNewProduct: (config: undefined | string | IReloadConfig) => (dispatch: ThreekitDispatch) => Promise<void>;
56
- export declare const changeActiveProductIdx: (idx: number) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
65
+ export declare const changeActiveCacheIdx: (idx: number) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
57
66
  export declare const removeProductIdx: (idx?: number | undefined) => (dispatch: ThreekitDispatch, getState: () => RootState) => Promise<void>;
58
67
  export default reducer;
@@ -50,7 +50,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.removeProductIdx = exports.changeActiveProductIdx = exports.loadNewProduct = exports.cacheActiveProduct = exports.initProduct = exports.getProductCache = exports.getActiveProductIdx = exports.getMetadata = exports.getName = exports.decrementActiveProductIdx = exports.incrementActiveProductIdx = exports.setActiveProductIdx = exports.removeProductFromCache = exports.updateActiveProductCache = exports.addProductToCache = exports.setMetadata = exports.setName = exports.PRODUCTS = void 0;
53
+ exports.removeProductIdx = exports.changeActiveCacheIdx = exports.loadNewProduct = exports.loadProduct = exports.cacheActiveProduct = exports.initProduct = exports.getProductCache = exports.getActiveCacheIdx = exports.getMetadata = exports.getName = exports.getProductId = exports.decrementActiveCacheIdx = exports.incrementActiveCacheIdx = exports.setActiveCacheIdx = exports.removeFromCache = exports.updateActiveProductCache = exports.appendToCache = exports.setMetadata = exports.setName = exports.setProductId = exports.PRODUCTS = void 0;
54
54
  var toolkit_1 = require("@reduxjs/toolkit");
55
55
  var connection_1 = __importDefault(require("../connection"));
56
56
  var treble_1 = require("./treble");
@@ -58,62 +58,68 @@ var treble_1 = require("./treble");
58
58
  * Actions
59
59
  ****************************************************/
60
60
  // Actions to be used only internally
61
- exports.setName = (0, toolkit_1.createAction)('treble/product/set-name');
62
- exports.setMetadata = (0, toolkit_1.createAction)('treble/product/set-metadata');
63
- exports.addProductToCache = (0, toolkit_1.createAction)('treble/add-product-to-cache');
61
+ exports.setProductId = (0, toolkit_1.createAction)('treble/set-product-id');
62
+ exports.setName = (0, toolkit_1.createAction)('treble/set-product-name');
63
+ exports.setMetadata = (0, toolkit_1.createAction)('treble/set-metadata');
64
+ exports.appendToCache = (0, toolkit_1.createAction)('treble/append-to-cache');
64
65
  exports.updateActiveProductCache = (0, toolkit_1.createAction)('treble/update-active-product-cache');
65
- exports.removeProductFromCache = (0, toolkit_1.createAction)('treble/remove-product-from-cache');
66
- exports.setActiveProductIdx = (0, toolkit_1.createAction)('treble/set-active-product-idx');
67
- exports.incrementActiveProductIdx = (0, toolkit_1.createAction)('treble/increment-active-product-idx');
68
- exports.decrementActiveProductIdx = (0, toolkit_1.createAction)('treble/decrement-active-product-idx');
66
+ exports.removeFromCache = (0, toolkit_1.createAction)('treble/remove-from-cache');
67
+ exports.setActiveCacheIdx = (0, toolkit_1.createAction)('treble/set-active-cache-idx');
68
+ exports.incrementActiveCacheIdx = (0, toolkit_1.createAction)('treble/increment-active-cache-idx');
69
+ exports.decrementActiveCacheIdx = (0, toolkit_1.createAction)('treble/decrement-active-cache-idx');
69
70
  /*****************************************************
70
71
  * State
71
72
  ****************************************************/
72
73
  var initialState = {
74
+ // ID of initialized item
75
+ id: undefined,
73
76
  // Name of the Initialized Item
74
77
  name: undefined,
75
78
  // Initialized item's metadata
76
79
  metadata: undefined,
77
80
  // cached products. Does not include the active product
78
- cachedProducts: [],
79
- activeProductIdx: 0,
81
+ cache: [],
82
+ activeCacheIdx: 0,
80
83
  };
81
84
  var reducer = (0, toolkit_1.createSlice)({
82
85
  name: 'product',
83
86
  initialState: initialState,
84
87
  extraReducers: function (builder) {
88
+ builder.addCase(exports.setProductId, function (state, action) {
89
+ return __assign(__assign({}, state), { id: action.payload });
90
+ });
85
91
  builder.addCase(exports.setName, function (state, action) {
86
92
  return __assign(__assign({}, state), { name: action.payload });
87
93
  });
88
94
  builder.addCase(exports.setMetadata, function (state, action) {
89
95
  return __assign(__assign({}, state), { metadata: action.payload });
90
96
  });
91
- builder.addCase(exports.addProductToCache, function (state, action) {
92
- state.cachedProducts.push(action.payload);
97
+ builder.addCase(exports.appendToCache, function (state, action) {
98
+ state.cache.push(action.payload);
93
99
  return state;
94
100
  });
95
- builder.addCase(exports.removeProductFromCache, function (state, action) {
96
- state.cachedProducts.splice(action.payload, 1);
101
+ builder.addCase(exports.removeFromCache, function (state, action) {
102
+ state.cache.splice(action.payload, 1);
97
103
  return state;
98
104
  });
99
105
  builder.addCase(exports.updateActiveProductCache, function (state, action) {
100
- state.cachedProducts[state.activeProductIdx] = Object.assign({}, state.cachedProducts[state.activeProductIdx], action.payload);
106
+ state.cache[state.activeCacheIdx] = Object.assign({}, state.cache[state.activeCacheIdx], action.payload);
101
107
  return state;
102
108
  });
103
- builder.addCase(exports.setActiveProductIdx, function (state, action) {
104
- state.activeProductIdx = action.payload;
109
+ builder.addCase(exports.setActiveCacheIdx, function (state, action) {
110
+ state.activeCacheIdx = action.payload;
105
111
  return state;
106
112
  });
107
- builder.addCase(exports.incrementActiveProductIdx, function (state) {
108
- state.activeProductIdx =
109
- state.activeProductIdx >= state.cachedProducts.length
110
- ? state.activeProductIdx
111
- : state.activeProductIdx + 1;
113
+ builder.addCase(exports.incrementActiveCacheIdx, function (state) {
114
+ state.activeCacheIdx =
115
+ state.activeCacheIdx >= state.cache.length
116
+ ? state.activeCacheIdx
117
+ : state.activeCacheIdx + 1;
112
118
  return state;
113
119
  });
114
- builder.addCase(exports.decrementActiveProductIdx, function (state) {
115
- state.activeProductIdx =
116
- state.activeProductIdx === 0 ? 0 : state.activeProductIdx - 1;
120
+ builder.addCase(exports.decrementActiveCacheIdx, function (state) {
121
+ state.activeCacheIdx =
122
+ state.activeCacheIdx === 0 ? 0 : state.activeCacheIdx - 1;
117
123
  return state;
118
124
  });
119
125
  },
@@ -122,6 +128,10 @@ var reducer = (0, toolkit_1.createSlice)({
122
128
  /*****************************************************
123
129
  * Standard Selectors
124
130
  ****************************************************/
131
+ var getProductId = function (state) {
132
+ return state.product.id;
133
+ };
134
+ exports.getProductId = getProductId;
125
135
  var getName = function (state) {
126
136
  return state.product.name;
127
137
  };
@@ -132,12 +142,12 @@ var getMetadata = function (state) {
132
142
  };
133
143
  exports.getMetadata = getMetadata;
134
144
  // Product Cache
135
- var getActiveProductIdx = function (state) {
136
- return state.product.activeProductIdx;
145
+ var getActiveCacheIdx = function (state) {
146
+ return state.product.activeCacheIdx;
137
147
  };
138
- exports.getActiveProductIdx = getActiveProductIdx;
148
+ exports.getActiveCacheIdx = getActiveCacheIdx;
139
149
  var getProductCache = function (state) {
140
- return state.product.cachedProducts.map(function (prod) {
150
+ return state.product.cache.map(function (prod) {
141
151
  return Object.assign({
142
152
  name: prod.name,
143
153
  }, prod.label ? { label: prod.label } : {}, prod.thumbnail ? { thumbnail: prod.thumbnail } : {});
@@ -158,8 +168,8 @@ var initProduct = function (prods) {
158
168
  var metadata = window.threekit.configurator.getMetadata();
159
169
  dispatch((0, exports.setName)(name));
160
170
  dispatch((0, exports.setMetadata)(metadata));
161
- if (!state.product.cachedProducts.length) {
162
- dispatch((0, exports.setActiveProductIdx)(0));
171
+ if (!state.product.cache.length) {
172
+ dispatch((0, exports.setActiveCacheIdx)(0));
163
173
  dispatch((0, exports.cacheActiveProduct)());
164
174
  }
165
175
  };
@@ -174,11 +184,43 @@ var cacheActiveProduct = function (config) {
174
184
  delete connectionObj.threekitDomain;
175
185
  var configuration = window.threekit.configurator.getConfiguration();
176
186
  var data = { connection: connectionObj, configuration: configuration };
177
- var product = Object.assign({ name: state.product.name, data: JSON.stringify(data) }, label ? { label: label } : {}, thumbnail ? { thumbnail: thumbnail } : {});
187
+ var product = Object.assign({
188
+ id: state.product.id,
189
+ name: state.product.name,
190
+ data: JSON.stringify(data),
191
+ }, label ? { label: label } : {}, thumbnail ? { thumbnail: thumbnail } : {});
178
192
  return dispatch((0, exports.updateActiveProductCache)(product));
179
193
  };
180
194
  };
181
195
  exports.cacheActiveProduct = cacheActiveProduct;
196
+ var loadProduct = function (id) {
197
+ return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
198
+ var state, productsList, shouldCacheProduct, productConfig;
199
+ return __generator(this, function (_a) {
200
+ switch (_a.label) {
201
+ case 0:
202
+ state = getState();
203
+ productsList = Object.keys(exports.PRODUCTS);
204
+ shouldCacheProduct = true;
205
+ if (!productsList.includes(id))
206
+ return [2 /*return*/];
207
+ productConfig = exports.PRODUCTS[id][state.treble.threekitEnv];
208
+ dispatch((0, exports.setProductId)(id));
209
+ if (shouldCacheProduct)
210
+ dispatch((0, exports.cacheActiveProduct)());
211
+ return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)(productConfig))];
212
+ case 1:
213
+ _a.sent();
214
+ if (shouldCacheProduct) {
215
+ dispatch((0, exports.incrementActiveCacheIdx)());
216
+ dispatch((0, exports.cacheActiveProduct)());
217
+ }
218
+ return [2 /*return*/];
219
+ }
220
+ });
221
+ }); };
222
+ };
223
+ exports.loadProduct = loadProduct;
182
224
  var loadNewProduct = function (config) {
183
225
  return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
184
226
  var label, thumbnail, shouldCacheProduct;
@@ -194,11 +236,12 @@ var loadNewProduct = function (config) {
194
236
  }
195
237
  if (shouldCacheProduct)
196
238
  dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
239
+ dispatch((0, exports.setProductId)(undefined));
197
240
  return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)(config))];
198
241
  case 1:
199
242
  _a.sent();
200
243
  if (shouldCacheProduct) {
201
- dispatch((0, exports.incrementActiveProductIdx)());
244
+ dispatch((0, exports.incrementActiveCacheIdx)());
202
245
  dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
203
246
  }
204
247
  return [2 /*return*/];
@@ -207,21 +250,22 @@ var loadNewProduct = function (config) {
207
250
  }); };
208
251
  };
209
252
  exports.loadNewProduct = loadNewProduct;
210
- var changeActiveProductIdx = function (idx) {
253
+ var changeActiveCacheIdx = function (idx) {
211
254
  return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
212
- var state, cachedProducts, cachedProduct, data;
255
+ var state, cache, cachedProduct, data;
213
256
  return __generator(this, function (_a) {
214
257
  switch (_a.label) {
215
258
  case 0:
216
259
  state = getState();
217
- cachedProducts = state.product.cachedProducts;
218
- if (idx >= cachedProducts.length)
260
+ cache = state.product.cache;
261
+ if (idx >= cache.length)
219
262
  return [2 /*return*/, Promise.resolve()];
220
263
  dispatch((0, exports.cacheActiveProduct)());
221
- cachedProduct = __assign({}, state.product.cachedProducts[idx]);
264
+ cachedProduct = __assign({}, state.product.cache[idx]);
222
265
  data = JSON.parse(cachedProduct.data);
223
266
  connection_1.default.connect(data.connection);
224
- dispatch((0, exports.setActiveProductIdx)(idx));
267
+ dispatch((0, exports.setActiveCacheIdx)(idx));
268
+ dispatch((0, exports.setProductId)(cachedProduct.id));
225
269
  return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)({
226
270
  assetId: data.connection.assetId,
227
271
  configuration: data.configuration,
@@ -233,38 +277,38 @@ var changeActiveProductIdx = function (idx) {
233
277
  });
234
278
  }); };
235
279
  };
236
- exports.changeActiveProductIdx = changeActiveProductIdx;
280
+ exports.changeActiveCacheIdx = changeActiveCacheIdx;
237
281
  var removeProductIdx = function (idx) {
238
282
  return function (dispatch, getState) { return __awaiter(void 0, void 0, void 0, function () {
239
- var state, _a, cachedProducts, activeProductIdx;
283
+ var state, _a, cache, activeCacheIdx;
240
284
  return __generator(this, function (_b) {
241
285
  switch (_b.label) {
242
286
  case 0:
243
287
  state = getState();
244
- _a = state.product, cachedProducts = _a.cachedProducts, activeProductIdx = _a.activeProductIdx;
245
- if (cachedProducts.length <= 1)
288
+ _a = state.product, cache = _a.cache, activeCacheIdx = _a.activeCacheIdx;
289
+ if (cache.length <= 1)
246
290
  return [2 /*return*/, Promise.resolve()];
247
- if (!(!idx || idx === activeProductIdx)) return [3 /*break*/, 5];
248
- if (!(activeProductIdx === state.product.cachedProducts.length - 1)) return [3 /*break*/, 2];
249
- return [4 /*yield*/, dispatch((0, exports.changeActiveProductIdx)(activeProductIdx - 1))];
291
+ if (!(!idx || idx === activeCacheIdx)) return [3 /*break*/, 5];
292
+ if (!(activeCacheIdx === state.product.cache.length - 1)) return [3 /*break*/, 2];
293
+ return [4 /*yield*/, dispatch((0, exports.changeActiveCacheIdx)(activeCacheIdx - 1))];
250
294
  case 1:
251
295
  _b.sent();
252
- dispatch((0, exports.removeProductFromCache)(activeProductIdx));
296
+ dispatch((0, exports.removeFromCache)(activeCacheIdx));
253
297
  return [3 /*break*/, 4];
254
298
  case 2:
255
- dispatch((0, exports.removeProductFromCache)(activeProductIdx));
256
- return [4 /*yield*/, dispatch((0, exports.changeActiveProductIdx)(activeProductIdx))];
299
+ dispatch((0, exports.removeFromCache)(activeCacheIdx));
300
+ return [4 /*yield*/, dispatch((0, exports.changeActiveCacheIdx)(activeCacheIdx))];
257
301
  case 3:
258
302
  _b.sent();
259
303
  _b.label = 4;
260
304
  case 4: return [3 /*break*/, 6];
261
305
  case 5:
262
- if (idx >= activeProductIdx) {
263
- dispatch((0, exports.removeProductFromCache)(idx));
306
+ if (idx >= activeCacheIdx) {
307
+ dispatch((0, exports.removeFromCache)(idx));
264
308
  }
265
- else if (idx <= activeProductIdx) {
266
- dispatch((0, exports.decrementActiveProductIdx)());
267
- dispatch((0, exports.removeProductFromCache)(idx));
309
+ else if (idx <= activeCacheIdx) {
310
+ dispatch((0, exports.decrementActiveCacheIdx)());
311
+ dispatch((0, exports.removeFromCache)(idx));
268
312
  }
269
313
  _b.label = 6;
270
314
  case 6: return [2 /*return*/, Promise.resolve()];
@@ -4,13 +4,15 @@ import { ITranslationMap } from '../api/products';
4
4
  * Types and Interfaces
5
5
  ****************************************************/
6
6
  export interface TranslationsState {
7
- translations: undefined | ITranslationMap;
8
7
  language: string | undefined;
9
8
  }
9
+ /*****************************************************
10
+ * Constants
11
+ ****************************************************/
12
+ export declare let TRANSLATIONS: undefined | ITranslationMap;
10
13
  /*****************************************************
11
14
  * Actions
12
15
  ****************************************************/
13
- export declare const setTranslations: import("@reduxjs/toolkit").ActionCreatorWithPayload<ITranslationMap, string>;
14
16
  export declare const setLanguage: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
15
17
  export declare const initTranslations: (language?: string | undefined) => (dispatch: ThreekitDispatch) => Promise<void>;
16
18
  declare const reducer: import("redux").Reducer<TranslationsState, import("redux").AnyAction>;
@@ -18,6 +20,5 @@ declare const reducer: import("redux").Reducer<TranslationsState, import("redux"
18
20
  * Standard Selectors
19
21
  ****************************************************/
20
22
  export declare const getLanguage: (state: RootState) => undefined | string;
21
- export declare const getTranslations: (state: RootState) => undefined | ITranslationMap;
22
23
  export declare const getLanguageOptions: (state: RootState) => Array<string>;
23
24
  export default reducer;
@@ -39,23 +39,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.getLanguageOptions = exports.getTranslations = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.setTranslations = void 0;
42
+ exports.getLanguageOptions = exports.getLanguage = exports.initTranslations = exports.setLanguage = exports.TRANSLATIONS = void 0;
43
43
  var toolkit_1 = require("@reduxjs/toolkit");
44
44
  var api_1 = __importDefault(require("../api"));
45
45
  /*****************************************************
46
46
  * Actions
47
47
  ****************************************************/
48
- // Actions to be used only internally
49
- exports.setTranslations = (0, toolkit_1.createAction)('treble/translations/set-translations');
50
48
  exports.setLanguage = (0, toolkit_1.createAction)('treble/translations/set-language');
51
49
  var initTranslations = function (language) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
52
- var translations;
53
50
  return __generator(this, function (_a) {
54
51
  switch (_a.label) {
55
52
  case 0: return [4 /*yield*/, api_1.default.products.fetchTranslations()];
56
53
  case 1:
57
- translations = _a.sent();
58
- dispatch((0, exports.setTranslations)(translations));
54
+ exports.TRANSLATIONS = _a.sent();
59
55
  if (language)
60
56
  dispatch((0, exports.setLanguage)(language));
61
57
  return [2 /*return*/];
@@ -68,16 +64,12 @@ exports.initTranslations = initTranslations;
68
64
  ****************************************************/
69
65
  var initialState = {
70
66
  // Selected language
71
- translations: undefined,
72
67
  language: undefined,
73
68
  };
74
69
  var reducer = (0, toolkit_1.createSlice)({
75
70
  name: 'translations',
76
71
  initialState: initialState,
77
72
  extraReducers: function (builder) {
78
- builder.addCase(exports.setTranslations, function (state, action) {
79
- state.translations = action.payload;
80
- });
81
73
  builder.addCase(exports.setLanguage, function (state, action) {
82
74
  state.language = action.payload;
83
75
  });
@@ -91,12 +83,10 @@ var getLanguage = function (state) {
91
83
  return state.translations.language;
92
84
  };
93
85
  exports.getLanguage = getLanguage;
94
- var getTranslations = function (state) { return state.translations.translations; };
95
- exports.getTranslations = getTranslations;
96
86
  var getLanguageOptions = function (state) {
97
- if (!state.treble.isThreekitInitialized || !state.translations.translations)
87
+ if (!state.treble.isThreekitInitialized || !exports.TRANSLATIONS)
98
88
  return [];
99
- return Object.keys(Object.values(state.translations.translations)[0]);
89
+ return Object.keys(Object.values(exports.TRANSLATIONS)[0]);
100
90
  };
101
91
  exports.getLanguageOptions = getLanguageOptions;
102
92
  exports.default = reducer;
@@ -13,6 +13,7 @@ export interface IPlayerInit {
13
13
  initialConfiguration?: IConfiguration;
14
14
  }
15
15
  export interface ILaunchConfig {
16
+ productId: string;
16
17
  threekitEnv: string;
17
18
  serverUrl: string;
18
19
  locale: string;
@@ -30,6 +31,7 @@ export interface IReloadConfig {
30
31
  cacheProduct?: boolean;
31
32
  }
32
33
  export interface TrebleState {
34
+ threekitEnv: string;
33
35
  isPlayerLoading: boolean;
34
36
  isThreekitInitialized: boolean;
35
37
  playerElId: undefined | string;
@@ -47,6 +49,7 @@ interface EventHandlers {
47
49
  /*****************************************************
48
50
  * Actions
49
51
  ****************************************************/
52
+ export declare const setThreekitEnv: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
50
53
  export declare const setThreekitInitialized: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
51
54
  export declare const setPlayerLoading: import("@reduxjs/toolkit").ActionCreatorWithPayload<boolean, string>;
52
55
  export declare const setPlayerElement: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, string>;
@@ -58,6 +61,7 @@ declare const reducer: import("redux").Reducer<TrebleState, import("redux").AnyA
58
61
  /*****************************************************
59
62
  * Standard Selectors
60
63
  ****************************************************/
64
+ export declare const getThreekitEnv: (state: RootState) => string;
61
65
  export declare const isThreekitInitialized: (state: RootState) => boolean;
62
66
  export declare const isPlayerLoading: (state: RootState) => boolean;
63
67
  export declare const getPlayerElementId: (state: RootState) => undefined | string;