From 275ad36baf18bcb460f94a3b7e0eca43bc30f9f4 Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Wed, 24 Jan 2024 12:01:49 +0800 Subject: [PATCH] =?UTF-8?q?i18n=E6=94=B9=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E7=BB=86=E8=8A=82,=E4=BB=A5=E5=8F=8A=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=80=A7=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/components/listPro/index.js | 2 +- es/features/cache.js | 4 ++-- es/features/locales.js | 8 ++++++-- lib/features/cache.js | 2 +- lib/features/locales.js | 8 ++++++-- src/features/cache.ts | 4 ++-- src/features/locales.ts | 9 +++++++-- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/es/components/listPro/index.js b/es/components/listPro/index.js index 5deb397e..5c343894 100644 --- a/es/components/listPro/index.js +++ b/es/components/listPro/index.js @@ -36,11 +36,11 @@ const ProList = (props) => { attribute: { label: '#', path: '#', + width: 100, }, attrType: 'number', attr: '#', entity: entity, - width:100, }, show: true, disabled: true, diff --git a/es/features/cache.js b/es/features/cache.js index a6731010..1605e71d 100644 --- a/es/features/cache.js +++ b/es/features/cache.js @@ -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); } /** * 向服务器刷新数据 diff --git a/es/features/locales.js b/es/features/locales.js index 8e09f002..e4cdf72e 100644 --- a/es/features/locales.js +++ b/es/features/locales.js @@ -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}缺失且可能请求不到更新的数据`); diff --git a/lib/features/cache.js b/lib/features/cache.js index 13132ab4..6621ba39 100644 --- a/lib/features/cache.js +++ b/lib/features/cache.js @@ -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); } /** * 向服务器刷新数据 diff --git a/lib/features/locales.js b/lib/features/locales.js index 4fc8fef7..39701626 100644 --- a/lib/features/locales.js +++ b/lib/features/locales.js @@ -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}缺失且可能请求不到更新的数据`); diff --git a/src/features/cache.ts b/src/features/cache.ts index 99437320..8edce42a 100644 --- a/src/features/cache.ts +++ b/src/features/cache.ts @@ -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); } /** diff --git a/src/features/locales.ts b/src/features/locales.ts index 07cd37fb..6c6adefc 100644 --- a/src/features/locales.ts +++ b/src/features/locales.ts @@ -102,8 +102,9 @@ export class Locales 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