@etsoo/appscript 1.4.5 → 1.4.6

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.
@@ -221,7 +221,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
221
221
  * @param culture New culture definition
222
222
  * @param onReady On ready callback
223
223
  */
224
- changeCulture(culture: DataTypes.CultureDefinition, onReady?: (resources: DataTypes.StringRecord) => void): void;
224
+ changeCulture(culture: DataTypes.CultureDefinition): Promise<DataTypes.StringRecord>;
225
225
  /**
226
226
  * Update current region label
227
227
  */
@@ -35,7 +35,6 @@ const ActionResultError_1 = require("../result/ActionResultError");
35
35
  const IApp_1 = require("./IApp");
36
36
  const UserRole_1 = require("./UserRole");
37
37
  let CJ;
38
- Promise.resolve().then(() => __importStar(require('crypto-js'))).then((result) => (CJ = result));
39
38
  /**
40
39
  * Core application
41
40
  */
@@ -153,12 +152,16 @@ class CoreApp {
153
152
  this.fields = IApp_1.appFields.reduce((a, v) => ({ ...a, [v]: 'smarterp-' + v + '-' + name }), {});
154
153
  // Device id
155
154
  this._deviceId = storage.getData(this.fields.deviceId, '');
156
- // Restore
157
- this.restore();
158
155
  this.setApi(api);
159
156
  const { currentCulture, currentRegion } = settings;
160
- this.changeCulture(currentCulture, () => this.setup());
161
- this.changeRegion(currentRegion);
157
+ // Load resources
158
+ Promise.all([
159
+ Promise.resolve().then(() => __importStar(require('crypto-js'))),
160
+ this.changeCulture(currentCulture)
161
+ ]).then(([cj, _resources]) => {
162
+ (CJ = cj), this.changeRegion(currentRegion);
163
+ this.setup();
164
+ });
162
165
  }
163
166
  getDeviceId() {
164
167
  return this.deviceId.substring(0, 15);
@@ -527,12 +530,13 @@ class CoreApp {
527
530
  * @param culture New culture definition
528
531
  * @param onReady On ready callback
529
532
  */
530
- changeCulture(culture, onReady) {
533
+ async changeCulture(culture) {
531
534
  // Name
532
535
  const { name } = culture;
533
536
  // Same?
534
- if (this._culture === name)
535
- return;
537
+ let resources = culture.resources;
538
+ if (this._culture === name && typeof resources === 'object')
539
+ return resources;
536
540
  // Save the cultrue to local storage
537
541
  this.storage.setPersistedData(shared_1.DomUtils.CultureField, name);
538
542
  // Change the API's Content-Language header
@@ -542,19 +546,13 @@ class CoreApp {
542
546
  this._culture = name;
543
547
  // Hold the current resources
544
548
  this.settings.currentCulture = culture;
545
- if (typeof culture.resources !== 'object') {
546
- culture.resources().then((result) => {
547
- culture.resources = result;
548
- this.updateRegionLabel();
549
- if (onReady)
550
- onReady(result);
551
- });
552
- }
553
- else {
554
- this.updateRegionLabel();
555
- if (onReady)
556
- onReady(culture.resources);
549
+ if (typeof resources !== 'object') {
550
+ resources = await resources();
551
+ // Set static resources back
552
+ culture.resources = resources;
557
553
  }
554
+ this.updateRegionLabel();
555
+ return resources;
558
556
  }
559
557
  /**
560
558
  * Update current region label
@@ -1208,7 +1206,10 @@ class CoreApp {
1208
1206
  /**
1209
1207
  * Setup callback
1210
1208
  */
1211
- setup() { }
1209
+ setup() {
1210
+ // Restore
1211
+ this.restore();
1212
+ }
1212
1213
  /**
1213
1214
  * Signout
1214
1215
  * @param apiUrl Signout API URL
@@ -159,9 +159,8 @@ export interface IApp {
159
159
  /**
160
160
  * Change culture
161
161
  * @param culture New culture definition
162
- * @param onReady On ready callback
163
162
  */
164
- changeCulture(culture: DataTypes.CultureDefinition, onReady?: (resources: DataTypes.StringRecord) => void): void;
163
+ changeCulture(culture: DataTypes.CultureDefinition): Promise<DataTypes.StringRecord>;
165
164
  /**
166
165
  * Check the action result is about device invalid
167
166
  * @param result Action result
@@ -221,7 +221,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
221
221
  * @param culture New culture definition
222
222
  * @param onReady On ready callback
223
223
  */
224
- changeCulture(culture: DataTypes.CultureDefinition, onReady?: (resources: DataTypes.StringRecord) => void): void;
224
+ changeCulture(culture: DataTypes.CultureDefinition): Promise<DataTypes.StringRecord>;
225
225
  /**
226
226
  * Update current region label
227
227
  */
@@ -9,7 +9,6 @@ import { ActionResultError } from '../result/ActionResultError';
9
9
  import { appFields } from './IApp';
10
10
  import { UserRole } from './UserRole';
11
11
  let CJ;
12
- import('crypto-js').then((result) => (CJ = result));
13
12
  /**
14
13
  * Core application
15
14
  */
@@ -127,12 +126,16 @@ export class CoreApp {
127
126
  this.fields = appFields.reduce((a, v) => ({ ...a, [v]: 'smarterp-' + v + '-' + name }), {});
128
127
  // Device id
129
128
  this._deviceId = storage.getData(this.fields.deviceId, '');
130
- // Restore
131
- this.restore();
132
129
  this.setApi(api);
133
130
  const { currentCulture, currentRegion } = settings;
134
- this.changeCulture(currentCulture, () => this.setup());
135
- this.changeRegion(currentRegion);
131
+ // Load resources
132
+ Promise.all([
133
+ import('crypto-js'),
134
+ this.changeCulture(currentCulture)
135
+ ]).then(([cj, _resources]) => {
136
+ (CJ = cj), this.changeRegion(currentRegion);
137
+ this.setup();
138
+ });
136
139
  }
137
140
  getDeviceId() {
138
141
  return this.deviceId.substring(0, 15);
@@ -501,12 +504,13 @@ export class CoreApp {
501
504
  * @param culture New culture definition
502
505
  * @param onReady On ready callback
503
506
  */
504
- changeCulture(culture, onReady) {
507
+ async changeCulture(culture) {
505
508
  // Name
506
509
  const { name } = culture;
507
510
  // Same?
508
- if (this._culture === name)
509
- return;
511
+ let resources = culture.resources;
512
+ if (this._culture === name && typeof resources === 'object')
513
+ return resources;
510
514
  // Save the cultrue to local storage
511
515
  this.storage.setPersistedData(DomUtils.CultureField, name);
512
516
  // Change the API's Content-Language header
@@ -516,19 +520,13 @@ export class CoreApp {
516
520
  this._culture = name;
517
521
  // Hold the current resources
518
522
  this.settings.currentCulture = culture;
519
- if (typeof culture.resources !== 'object') {
520
- culture.resources().then((result) => {
521
- culture.resources = result;
522
- this.updateRegionLabel();
523
- if (onReady)
524
- onReady(result);
525
- });
526
- }
527
- else {
528
- this.updateRegionLabel();
529
- if (onReady)
530
- onReady(culture.resources);
523
+ if (typeof resources !== 'object') {
524
+ resources = await resources();
525
+ // Set static resources back
526
+ culture.resources = resources;
531
527
  }
528
+ this.updateRegionLabel();
529
+ return resources;
532
530
  }
533
531
  /**
534
532
  * Update current region label
@@ -1182,7 +1180,10 @@ export class CoreApp {
1182
1180
  /**
1183
1181
  * Setup callback
1184
1182
  */
1185
- setup() { }
1183
+ setup() {
1184
+ // Restore
1185
+ this.restore();
1186
+ }
1186
1187
  /**
1187
1188
  * Signout
1188
1189
  * @param apiUrl Signout API URL
@@ -159,9 +159,8 @@ export interface IApp {
159
159
  /**
160
160
  * Change culture
161
161
  * @param culture New culture definition
162
- * @param onReady On ready callback
163
162
  */
164
- changeCulture(culture: DataTypes.CultureDefinition, onReady?: (resources: DataTypes.StringRecord) => void): void;
163
+ changeCulture(culture: DataTypes.CultureDefinition): Promise<DataTypes.StringRecord>;
165
164
  /**
166
165
  * Check the action result is about device invalid
167
166
  * @param result Action result
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -42,7 +42,6 @@ import type CryptoJS from 'crypto-js';
42
42
 
43
43
  type CJType = typeof CryptoJS;
44
44
  let CJ: CJType;
45
- import('crypto-js').then((result) => (CJ = result));
46
45
 
47
46
  /**
48
47
  * Core application interface
@@ -271,15 +270,18 @@ export abstract class CoreApp<
271
270
  // Device id
272
271
  this._deviceId = storage.getData(this.fields.deviceId, '');
273
272
 
274
- // Restore
275
- this.restore();
276
-
277
273
  this.setApi(api);
278
274
 
279
275
  const { currentCulture, currentRegion } = settings;
280
- this.changeCulture(currentCulture, () => this.setup());
281
276
 
282
- this.changeRegion(currentRegion);
277
+ // Load resources
278
+ Promise.all([
279
+ import('crypto-js'),
280
+ this.changeCulture(currentCulture)
281
+ ]).then(([cj, _resources]) => {
282
+ (CJ = cj), this.changeRegion(currentRegion);
283
+ this.setup();
284
+ });
283
285
  }
284
286
 
285
287
  private getDeviceId() {
@@ -744,15 +746,14 @@ export abstract class CoreApp<
744
746
  * @param culture New culture definition
745
747
  * @param onReady On ready callback
746
748
  */
747
- changeCulture(
748
- culture: DataTypes.CultureDefinition,
749
- onReady?: (resources: DataTypes.StringRecord) => void
750
- ) {
749
+ async changeCulture(culture: DataTypes.CultureDefinition) {
751
750
  // Name
752
751
  const { name } = culture;
753
752
 
754
753
  // Same?
755
- if (this._culture === name) return;
754
+ let resources = culture.resources;
755
+ if (this._culture === name && typeof resources === 'object')
756
+ return resources;
756
757
 
757
758
  // Save the cultrue to local storage
758
759
  this.storage.setPersistedData(DomUtils.CultureField, name);
@@ -767,16 +768,15 @@ export abstract class CoreApp<
767
768
  // Hold the current resources
768
769
  this.settings.currentCulture = culture;
769
770
 
770
- if (typeof culture.resources !== 'object') {
771
- culture.resources().then((result) => {
772
- culture.resources = result;
773
- this.updateRegionLabel();
774
- if (onReady) onReady(result);
775
- });
776
- } else {
777
- this.updateRegionLabel();
778
- if (onReady) onReady(culture.resources);
771
+ if (typeof resources !== 'object') {
772
+ resources = await resources();
773
+
774
+ // Set static resources back
775
+ culture.resources = resources;
779
776
  }
777
+ this.updateRegionLabel();
778
+
779
+ return resources;
780
780
  }
781
781
 
782
782
  /**
@@ -1544,7 +1544,10 @@ export abstract class CoreApp<
1544
1544
  /**
1545
1545
  * Setup callback
1546
1546
  */
1547
- setup() {}
1547
+ setup() {
1548
+ // Restore
1549
+ this.restore();
1550
+ }
1548
1551
 
1549
1552
  /**
1550
1553
  * Signout
package/src/app/IApp.ts CHANGED
@@ -214,12 +214,10 @@ export interface IApp {
214
214
  /**
215
215
  * Change culture
216
216
  * @param culture New culture definition
217
- * @param onReady On ready callback
218
217
  */
219
218
  changeCulture(
220
- culture: DataTypes.CultureDefinition,
221
- onReady?: (resources: DataTypes.StringRecord) => void
222
- ): void;
219
+ culture: DataTypes.CultureDefinition
220
+ ): Promise<DataTypes.StringRecord>;
223
221
 
224
222
  /**
225
223
  * Check the action result is about device invalid