application初始化的时候取应用信息
This commit is contained in:
parent
177c4bd8ff
commit
d9eea0625a
|
|
@ -14,6 +14,7 @@ export declare class Application<ED extends EntityDict, Cxt extends RuntimeConte
|
|||
private cache;
|
||||
private storage;
|
||||
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>, type: AppType, cache: Cache<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, storage: LocalStorage<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>);
|
||||
private syncApplicationInfoFromBackend;
|
||||
private getApplicationFromCache;
|
||||
private refresh;
|
||||
getApplication(): Promise<SelectRowShape<ED["application"]["Schema"], {
|
||||
|
|
|
|||
|
|
@ -28,13 +28,34 @@ var Application = /** @class */ (function (_super) {
|
|||
_this.rwLock.acquire('X');
|
||||
if (applicationId) {
|
||||
_this.applicationId = applicationId;
|
||||
_this.syncApplicationInfoFromBackend();
|
||||
}
|
||||
else {
|
||||
_this.refresh(type);
|
||||
}
|
||||
_this.rwLock.release();
|
||||
return _this;
|
||||
}
|
||||
Application.prototype.syncApplicationInfoFromBackend = function () {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var data;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.cache.refresh('application', {
|
||||
data: projection,
|
||||
filter: {
|
||||
id: this.applicationId,
|
||||
}
|
||||
})];
|
||||
case 1:
|
||||
data = (_a.sent()).data;
|
||||
(0, assert_1.assert)(data.length === 1, "applicationId".concat(this.applicationId, "\u6CA1\u6709\u53D6\u5230\u6709\u6548\u6570\u636E"));
|
||||
this.application = data[0];
|
||||
this.rwLock.release();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
Application.prototype.getApplicationFromCache = function () {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var data;
|
||||
|
|
@ -48,8 +69,9 @@ var Application = /** @class */ (function (_super) {
|
|||
})];
|
||||
case 1:
|
||||
data = _a.sent();
|
||||
(0, assert_1.assert)(data.length === 1);
|
||||
(0, assert_1.assert)(data.length === 1, "applicationId".concat(this.applicationId, "\u6CA1\u6709\u53D6\u5230\u6709\u6548\u6570\u636E"));
|
||||
this.application = data[0];
|
||||
this.rwLock.release();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -55,10 +55,22 @@ export class Application<ED extends EntityDict, Cxt extends RuntimeContext<ED>,
|
|||
this.rwLock.acquire('X');
|
||||
if (applicationId) {
|
||||
this.applicationId = applicationId;
|
||||
this.syncApplicationInfoFromBackend();
|
||||
}
|
||||
else {
|
||||
this.refresh(type);
|
||||
}
|
||||
}
|
||||
|
||||
private async syncApplicationInfoFromBackend() {
|
||||
const { data } = await this.cache.refresh('application', {
|
||||
data: projection,
|
||||
filter: {
|
||||
id: this.applicationId,
|
||||
}
|
||||
});
|
||||
assert(data.length === 1, `applicationId${this.applicationId}没有取到有效数据`);
|
||||
this.application = data[0] as any;
|
||||
this.rwLock.release();
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +81,9 @@ export class Application<ED extends EntityDict, Cxt extends RuntimeContext<ED>,
|
|||
id: this.applicationId,
|
||||
}
|
||||
} as any);
|
||||
assert(data.length === 1);
|
||||
assert(data.length === 1, `applicationId${this.applicationId}没有取到有效数据`);
|
||||
this.application = data[0];
|
||||
this.rwLock.release();
|
||||
}
|
||||
|
||||
private async refresh(type: AppType) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue