application initialize 接收外层注入projection
This commit is contained in:
parent
28fe879dcd
commit
6f51e07e28
|
|
@ -14,11 +14,12 @@ export declare class Application<ED extends EntityDict, Cxt extends BackendRunti
|
|||
private application?;
|
||||
private cache;
|
||||
private storage;
|
||||
private projection;
|
||||
constructor(type: AppType, domain: string, cache: Cache<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>, storage: LocalStorage);
|
||||
private refresh;
|
||||
private getApplicationFromCache;
|
||||
private loadApplicationInfo;
|
||||
initialize(appId?: string | null): Promise<void>;
|
||||
initialize(appId?: string | null, projection?: EntityDict['application']['Selection']['data']): Promise<void>;
|
||||
getApplication(): Partial<import("../oak-app-domain/Application/Schema").Schema> | undefined;
|
||||
getApplicationId(): string | undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ exports.Application = void 0;
|
|||
var tslib_1 = require("tslib");
|
||||
var Feature_1 = require("oak-frontend-base/lib/types/Feature");
|
||||
var assert_1 = require("oak-domain/lib/utils/assert");
|
||||
var lodash_1 = require("oak-domain/lib/utils/lodash");
|
||||
var projection_1 = require("../types/projection");
|
||||
var Application = /** @class */ (function (_super) {
|
||||
tslib_1.__extends(Application, _super);
|
||||
|
|
@ -15,6 +16,7 @@ var Application = /** @class */ (function (_super) {
|
|||
_this.applicationId = applicationId;
|
||||
_this.type = type;
|
||||
_this.domain = domain;
|
||||
_this.projection = projection_1.applicationProjection;
|
||||
return _this;
|
||||
}
|
||||
Application.prototype.refresh = function () {
|
||||
|
|
@ -23,7 +25,7 @@ var Application = /** @class */ (function (_super) {
|
|||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.cache.refresh('application', {
|
||||
data: projection_1.applicationProjection,
|
||||
data: this.projection,
|
||||
filter: {
|
||||
id: this.applicationId,
|
||||
},
|
||||
|
|
@ -42,7 +44,7 @@ var Application = /** @class */ (function (_super) {
|
|||
};
|
||||
Application.prototype.getApplicationFromCache = function () {
|
||||
var data = this.cache.get('application', {
|
||||
data: projection_1.applicationProjection,
|
||||
data: this.projection,
|
||||
filter: {
|
||||
id: this.applicationId,
|
||||
},
|
||||
|
|
@ -74,11 +76,13 @@ var Application = /** @class */ (function (_super) {
|
|||
});
|
||||
});
|
||||
};
|
||||
Application.prototype.initialize = function (appId) {
|
||||
Application.prototype.initialize = function (appId, projection) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
//接收外层注入的projection
|
||||
this.projection = (0, lodash_1.merge)(this.projection, projection);
|
||||
if (process.env.NODE_ENV === 'development' && appId) {
|
||||
// development环境下允许注入一个线上的appId
|
||||
this.applicationId = appId;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Cache } from 'oak-frontend-base/lib/features/cache';
|
|||
import { Feature } from 'oak-frontend-base/lib/types/Feature';
|
||||
import { CommonAspectDict } from 'oak-common-aspect';
|
||||
import { assert } from 'oak-domain/lib/utils/assert';
|
||||
import { merge } from 'oak-domain/lib/utils/lodash';
|
||||
|
||||
import { EntityDict } from '../oak-app-domain';
|
||||
import { AppType } from '../oak-app-domain/Application/Schema';
|
||||
|
|
@ -24,6 +25,7 @@ export class Application<
|
|||
private application?: Partial<EntityDict['application']['Schema']>;
|
||||
private cache: Cache<ED, Cxt, FrontCxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
private storage: LocalStorage;
|
||||
private projection: EntityDict['application']['Selection']['data'];
|
||||
|
||||
constructor(
|
||||
type: AppType,
|
||||
|
|
@ -38,11 +40,12 @@ export class Application<
|
|||
this.applicationId = applicationId;
|
||||
this.type = type;
|
||||
this.domain = domain;
|
||||
this.projection = applicationProjection;
|
||||
}
|
||||
|
||||
private async refresh() {
|
||||
const { data } = await this.cache.refresh('application', {
|
||||
data: applicationProjection,
|
||||
data: this.projection,
|
||||
filter: {
|
||||
id: this.applicationId!,
|
||||
},
|
||||
|
|
@ -59,7 +62,7 @@ export class Application<
|
|||
|
||||
private getApplicationFromCache() {
|
||||
const data = this.cache.get('application', {
|
||||
data: applicationProjection,
|
||||
data: this.projection,
|
||||
filter: {
|
||||
id: this.applicationId,
|
||||
},
|
||||
|
|
@ -89,7 +92,12 @@ export class Application<
|
|||
this.publish();
|
||||
}
|
||||
|
||||
async initialize(appId?: string | null) {
|
||||
async initialize(
|
||||
appId?: string | null,
|
||||
projection?: EntityDict['application']['Selection']['data']
|
||||
) {
|
||||
//接收外层注入的projection
|
||||
this.projection = merge(this.projection, projection);
|
||||
if (process.env.NODE_ENV === 'development' && appId) {
|
||||
// development环境下允许注入一个线上的appId
|
||||
this.applicationId = appId;
|
||||
|
|
|
|||
Loading…
Reference in New Issue