i18n改了一些细节,以及测试性代码

This commit is contained in:
Xu Chang 2024-01-24 12:01:49 +08:00
parent caf783e9da
commit 275ad36baf
7 changed files with 25 additions and 12 deletions

View File

@ -36,11 +36,11 @@ const ProList = (props) => {
attribute: {
label: '#',
path: '#',
width: 100,
},
attrType: 'number',
attr: '#',
entity: entity,
width:100,
},
show: true,
disabled: true,

View File

@ -1,5 +1,5 @@
import { Feature } from '../types/Feature';
import { pull, intersection } from 'oak-domain/lib/utils/lodash';
import { pull, intersection, unset } from 'oak-domain/lib/utils/lodash';
import { CacheStore } from '../cacheStore/CacheStore';
import { OakRowUnexistedException, OakException, OakUserException } from 'oak-domain/lib/types/Exception';
import { assert } from 'oak-domain/lib/utils/assert';
@ -130,7 +130,7 @@ export class Cache extends Feature {
if (originTimestamp) {
return () => this.addRefreshRecord(entity, key, originTimestamp);
}
return () => undefined;
return () => unset(this.refreshRecords[entity], key);
}
/**
* 向服务器刷新数据

View File

@ -77,8 +77,9 @@ export class Locales extends Feature {
this.i18n.store(dataset);
if (i18ns.length > 0) {
// 启动时刷新数据策略
const nss = i18ns.map(ele => ele.namespace);
await this.loadServerData(nss);
// 先不处理了这样似乎会导致如果key不miss就不会更新所以i18n的更新要确保这点
/* const nss = i18ns.map(ele => ele.namespace!);
await this.loadServerData(nss); */
}
}
async loadServerData(nss) {
@ -127,6 +128,9 @@ export class Locales extends Feature {
async loadData(key) {
assert(typeof key === 'string');
const [ns] = key.split('.');
if (process.env.NODE_ENV === 'development') {
assert(!['undefined', 'notExist'].includes(ns));
}
await this.loadServerData([ns]);
if (!this.hasKey(key)) {
console.warn(`命名空间${ns}中的${key}缺失且可能请求不到更新的数据`);

View File

@ -133,7 +133,7 @@ class Cache extends Feature_1.Feature {
if (originTimestamp) {
return () => this.addRefreshRecord(entity, key, originTimestamp);
}
return () => undefined;
return () => (0, lodash_1.unset)(this.refreshRecords[entity], key);
}
/**
* 向服务器刷新数据

View File

@ -80,8 +80,9 @@ class Locales extends Feature_1.Feature {
this.i18n.store(dataset);
if (i18ns.length > 0) {
// 启动时刷新数据策略
const nss = i18ns.map(ele => ele.namespace);
await this.loadServerData(nss);
// 先不处理了这样似乎会导致如果key不miss就不会更新所以i18n的更新要确保这点
/* const nss = i18ns.map(ele => ele.namespace!);
await this.loadServerData(nss); */
}
}
async loadServerData(nss) {
@ -130,6 +131,9 @@ class Locales extends Feature_1.Feature {
async loadData(key) {
(0, assert_1.assert)(typeof key === 'string');
const [ns] = key.split('.');
if (process.env.NODE_ENV === 'development') {
(0, assert_1.assert)(!['undefined', 'notExist'].includes(ns));
}
await this.loadServerData([ns]);
if (!this.hasKey(key)) {
console.warn(`命名空间${ns}中的${key}缺失且可能请求不到更新的数据`);

View File

@ -2,7 +2,7 @@ import { EntityDict, OperateOption, SelectOption, OpRecord, AspectWrapper, Check
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { CommonAspectDict } from 'oak-common-aspect';
import { Feature } from '../types/Feature';
import { merge, pull, intersection, omit, pick } from 'oak-domain/lib/utils/lodash';
import { merge, pull, intersection, omit, unset } from 'oak-domain/lib/utils/lodash';
import { CacheStore } from '../cacheStore/CacheStore';
import { OakRowUnexistedException, OakRowInconsistencyException, OakException, OakUserException } from 'oak-domain/lib/types/Exception';
import { AsyncContext } from 'oak-domain/lib/store/AsyncRowStore';
@ -203,7 +203,7 @@ export class Cache<
if (originTimestamp) {
return () => this.addRefreshRecord(entity, key, originTimestamp);
}
return () => undefined as void;
return () => unset(this.refreshRecords[entity], key);
}
/**

View File

@ -102,8 +102,9 @@ export class Locales<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncCo
if (i18ns.length > 0) {
// 启动时刷新数据策略
const nss = i18ns.map(ele => ele.namespace!);
await this.loadServerData(nss);
// 先不处理了这样似乎会导致如果key不miss就不会更新所以i18n的更新要确保这点
/* const nss = i18ns.map(ele => ele.namespace!);
await this.loadServerData(nss); */
}
}
@ -157,6 +158,10 @@ export class Locales<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncCo
assert(typeof key === 'string');
const [ ns ] = key.split('.');
if (process.env.NODE_ENV === 'development') {
assert(!['undefined', 'notExist'].includes(ns));
}
await this.loadServerData([ns]);
if (!this.hasKey(key)) {
console.warn(`命名空间${ns}中的${key}缺失且可能请求不到更新的数据`);