@vived/app 4.10.0 → 4.11.0
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.
- package/lib/AppObject/AppObjectComponent.d.ts +3 -0
- package/lib/AppObject/AppObjectComponent.js +33 -0
- package/lib/Components/Dispatcher/UC/SubmitActivityAssetUC.d.ts +10 -0
- package/lib/Components/Dispatcher/UC/SubmitActivityAssetUC.js +63 -0
- package/lib/Components/Dispatcher/UC/index.d.ts +1 -0
- package/lib/Components/Dispatcher/UC/index.js +1 -0
- package/package.json +1 -1
|
@@ -4,6 +4,9 @@ export declare class AppObjectComponent {
|
|
|
4
4
|
readonly type: string;
|
|
5
5
|
readonly appObject: AppObject;
|
|
6
6
|
get appObjects(): AppObjectRepo;
|
|
7
|
+
private cachedSingletons;
|
|
8
|
+
getCachedSingleton<T extends AppObjectComponent>(type: string): T | undefined;
|
|
9
|
+
getSingleton<T extends AppObjectComponent>(type: string, logType?: "LOG" | "WARN" | "ERROR"): T | undefined;
|
|
7
10
|
dispose(): void;
|
|
8
11
|
log(message: string): void;
|
|
9
12
|
warn(message: string): void;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AppObjectComponent = void 0;
|
|
4
4
|
class AppObjectComponent {
|
|
5
5
|
constructor(appObject, type) {
|
|
6
|
+
this.cachedSingletons = new Map();
|
|
6
7
|
this.appObject = appObject;
|
|
7
8
|
this.type = type;
|
|
8
9
|
appObject.addComponent(this);
|
|
@@ -10,6 +11,37 @@ class AppObjectComponent {
|
|
|
10
11
|
get appObjects() {
|
|
11
12
|
return this.appObject.appObjectRepo;
|
|
12
13
|
}
|
|
14
|
+
getCachedSingleton(type) {
|
|
15
|
+
if (!this.cachedSingletons.has(type)) {
|
|
16
|
+
const component = this.appObjects.getSingleton(type);
|
|
17
|
+
if (!component) {
|
|
18
|
+
this.warn("Unable to get cached singleton type " + type);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
this.cachedSingletons.set(type, component);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return this.cachedSingletons.get(type);
|
|
25
|
+
}
|
|
26
|
+
getSingleton(type, logType = "WARN") {
|
|
27
|
+
const comp = this.appObjects.getSingleton(type);
|
|
28
|
+
if (!comp) {
|
|
29
|
+
const msg = "Unable to get singleton type " + type;
|
|
30
|
+
switch (logType) {
|
|
31
|
+
case "ERROR":
|
|
32
|
+
this.error(msg);
|
|
33
|
+
break;
|
|
34
|
+
case "LOG":
|
|
35
|
+
this.log(msg);
|
|
36
|
+
break;
|
|
37
|
+
case "WARN":
|
|
38
|
+
this.warn(msg);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return comp;
|
|
43
|
+
}
|
|
44
|
+
;
|
|
13
45
|
dispose() {
|
|
14
46
|
if (this.appObject.getComponent(this.type) === this) {
|
|
15
47
|
this.appObject.removeComponent(this.type);
|
|
@@ -21,6 +53,7 @@ class AppObjectComponent {
|
|
|
21
53
|
warn(message) {
|
|
22
54
|
this.appObjects.submitWarning(`${this.appObject.id}/${this.type}`, message);
|
|
23
55
|
}
|
|
56
|
+
;
|
|
24
57
|
error(message) {
|
|
25
58
|
this.appObjects.submitError(`${this.appObject.id}/${this.type}`, message);
|
|
26
59
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AppObject, AppObjectRepo, AppObjectUC } from "../../../AppObject";
|
|
2
|
+
export declare abstract class SubmitActivityAssetUC extends AppObjectUC {
|
|
3
|
+
static readonly type = "SubmitActivityAssetUC";
|
|
4
|
+
readonly requestType = "SUBMIT_ACTIVITY_ASSET";
|
|
5
|
+
abstract doDispatch(assetFile: File): Promise<string>;
|
|
6
|
+
static get: (appObjects: AppObjectRepo) => SubmitActivityAssetUC | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare function makeSubmitActivityAssetUC(appObject: AppObject): SubmitActivityAssetUC;
|
|
9
|
+
export declare function submitActivityAsset(assetFile: File, appObjects: AppObjectRepo): Promise<string>;
|
|
10
|
+
export declare const NO_ASSET_ID_ERROR: Error;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NO_ASSET_ID_ERROR = exports.submitActivityAsset = exports.makeSubmitActivityAssetUC = exports.SubmitActivityAssetUC = void 0;
|
|
4
|
+
const AppObject_1 = require("../../../AppObject");
|
|
5
|
+
const Entities_1 = require("../Entities");
|
|
6
|
+
class SubmitActivityAssetUC extends AppObject_1.AppObjectUC {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.requestType = "SUBMIT_ACTIVITY_ASSET";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.SubmitActivityAssetUC = SubmitActivityAssetUC;
|
|
13
|
+
SubmitActivityAssetUC.type = "SubmitActivityAssetUC";
|
|
14
|
+
SubmitActivityAssetUC.get = (appObjects) => AppObject_1.getSingletonComponent(SubmitActivityAssetUC.type, appObjects);
|
|
15
|
+
function makeSubmitActivityAssetUC(appObject) {
|
|
16
|
+
return new SubmitActivityAssetUCImp(appObject);
|
|
17
|
+
}
|
|
18
|
+
exports.makeSubmitActivityAssetUC = makeSubmitActivityAssetUC;
|
|
19
|
+
function submitActivityAsset(assetFile, appObjects) {
|
|
20
|
+
const dispatchUC = SubmitActivityAssetUC.get(appObjects);
|
|
21
|
+
if (dispatchUC) {
|
|
22
|
+
return dispatchUC.doDispatch(assetFile);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
appObjects.submitWarning("submitActivityAsset", "Can't find SubmitActivityAssetUC");
|
|
26
|
+
return Promise.reject();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.submitActivityAsset = submitActivityAsset;
|
|
30
|
+
class SubmitActivityAssetUCImp extends SubmitActivityAssetUC {
|
|
31
|
+
constructor(appObject) {
|
|
32
|
+
super(appObject, SubmitActivityAssetUC.type);
|
|
33
|
+
this.requestVersion = 1;
|
|
34
|
+
this.appDispatcher = appObject.getComponent(Entities_1.AppDispatcher.type);
|
|
35
|
+
if (!this.appDispatcher) {
|
|
36
|
+
this.warn("SubmitActivityAssetUC has been added to an App Object that does not have a AppDispatcher. Add a dispatcher first");
|
|
37
|
+
this.dispose();
|
|
38
|
+
}
|
|
39
|
+
this.appObjects.registerSingleton(this);
|
|
40
|
+
}
|
|
41
|
+
doDispatch(assetFile) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const callback = (assetID) => {
|
|
44
|
+
if (assetID === undefined) {
|
|
45
|
+
reject(exports.NO_ASSET_ID_ERROR);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
resolve(assetID);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const payload = {
|
|
52
|
+
assetFile,
|
|
53
|
+
callback
|
|
54
|
+
};
|
|
55
|
+
if (!this.appDispatcher)
|
|
56
|
+
return reject(new Error("No host handler has been registered"));
|
|
57
|
+
else {
|
|
58
|
+
this.appDispatcher.formRequestAndDispatch(this.requestType, this.requestVersion, payload);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.NO_ASSET_ID_ERROR = new Error("Asset ID is undefined");
|
|
@@ -22,5 +22,6 @@ export * from "./ShowSelectModelUC";
|
|
|
22
22
|
export * from "./ShowSpinnerUC";
|
|
23
23
|
export * from "./StateHasChangedUC";
|
|
24
24
|
export * from "./StateIsCompleteUC";
|
|
25
|
+
export * from "./SubmitActivityAssetUC";
|
|
25
26
|
export * from "./SubmitResultResultUC";
|
|
26
27
|
export * from "./RestoreCurrentStateUC";
|
|
@@ -34,5 +34,6 @@ __exportStar(require("./ShowSelectModelUC"), exports);
|
|
|
34
34
|
__exportStar(require("./ShowSpinnerUC"), exports);
|
|
35
35
|
__exportStar(require("./StateHasChangedUC"), exports);
|
|
36
36
|
__exportStar(require("./StateIsCompleteUC"), exports);
|
|
37
|
+
__exportStar(require("./SubmitActivityAssetUC"), exports);
|
|
37
38
|
__exportStar(require("./SubmitResultResultUC"), exports);
|
|
38
39
|
__exportStar(require("./RestoreCurrentStateUC"), exports);
|