@kosdev-code/kos-ui-sdk 0.1.0-next.850 → 0.1.0-next.851
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/core/core/dependency-manager.d.ts +6 -0
- package/core/core/dependency-manager.d.ts.map +1 -1
- package/core/core/kosModelManager.d.ts.map +1 -1
- package/core/core/model/model-hook-cache.d.ts +30 -0
- package/core/core/model/model-hook-cache.d.ts.map +1 -0
- package/core/index.d.ts +1 -0
- package/core/index.d.ts.map +1 -1
- package/index.cjs +63 -20
- package/index.cjs.map +1 -1
- package/index.js +63 -20
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/ui/hooks/use-kos-model.d.ts.map +1 -1
package/index.js
CHANGED
|
@@ -4190,6 +4190,33 @@ class KosDependencyManager {
|
|
|
4190
4190
|
uses.filter((id) => id !== dependencyId)
|
|
4191
4191
|
);
|
|
4192
4192
|
}
|
|
4193
|
+
/**
|
|
4194
|
+
* Drops every edge into and out of a model. Called when the model is
|
|
4195
|
+
* destroyed, so its dependencies are not left pinned by a model that is
|
|
4196
|
+
* gone and can never release them.
|
|
4197
|
+
*/
|
|
4198
|
+
removeAll(modelId) {
|
|
4199
|
+
for (const dependencyId of this._usesCache.get(modelId) ?? []) {
|
|
4200
|
+
const usedBy = this._usedByCache.get(dependencyId);
|
|
4201
|
+
if (usedBy) {
|
|
4202
|
+
this._usedByCache.set(
|
|
4203
|
+
dependencyId,
|
|
4204
|
+
usedBy.filter((id) => id !== modelId)
|
|
4205
|
+
);
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
this._usesCache.delete(modelId);
|
|
4209
|
+
for (const dependentId of this._usedByCache.get(modelId) ?? []) {
|
|
4210
|
+
const uses = this._usesCache.get(dependentId);
|
|
4211
|
+
if (uses) {
|
|
4212
|
+
this._usesCache.set(
|
|
4213
|
+
dependentId,
|
|
4214
|
+
uses.filter((id) => id !== modelId)
|
|
4215
|
+
);
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
this._usedByCache.delete(modelId);
|
|
4219
|
+
}
|
|
4193
4220
|
canDestroy(modelId) {
|
|
4194
4221
|
const usedBy = this._usedByCache.get(modelId);
|
|
4195
4222
|
if (usedBy?.length) {
|
|
@@ -4267,6 +4294,19 @@ class KosModelCache {
|
|
|
4267
4294
|
return this._preloaded;
|
|
4268
4295
|
}
|
|
4269
4296
|
}
|
|
4297
|
+
const cache$1 = /* @__PURE__ */ new Map();
|
|
4298
|
+
const modelHookCache = {
|
|
4299
|
+
has: (key) => cache$1.has(key),
|
|
4300
|
+
get: (key) => cache$1.get(key),
|
|
4301
|
+
set: (key, entry) => cache$1.set(key, entry),
|
|
4302
|
+
delete: (key) => cache$1.delete(key),
|
|
4303
|
+
clear: () => cache$1.clear()
|
|
4304
|
+
};
|
|
4305
|
+
const clearModelHookCacheEntry = (modelId) => {
|
|
4306
|
+
if (modelId) {
|
|
4307
|
+
cache$1.delete(modelId);
|
|
4308
|
+
}
|
|
4309
|
+
};
|
|
4270
4310
|
class KosModelError extends Error {
|
|
4271
4311
|
context;
|
|
4272
4312
|
originalCause;
|
|
@@ -11742,6 +11782,8 @@ class KosModelManager {
|
|
|
11742
11782
|
if (model?.modelId && this.dependencies.canDestroy(model.modelId)) {
|
|
11743
11783
|
await model.unload?.();
|
|
11744
11784
|
this.removeModel(model);
|
|
11785
|
+
this.dependencies.removeAll(model.modelId);
|
|
11786
|
+
clearModelHookCacheEntry(model.modelId);
|
|
11745
11787
|
}
|
|
11746
11788
|
}
|
|
11747
11789
|
/**
|
|
@@ -26821,30 +26863,29 @@ const waitForRetry = (depth = 0) => new Promise((resolve) => {
|
|
|
26821
26863
|
resolve(true);
|
|
26822
26864
|
}, 2 ** depth * 10);
|
|
26823
26865
|
});
|
|
26824
|
-
const cache$1 = /* @__PURE__ */ new Map();
|
|
26825
26866
|
function fetchData$1(key, fetcher) {
|
|
26826
|
-
|
|
26827
|
-
|
|
26867
|
+
const entry = modelHookCache.get(key);
|
|
26868
|
+
if (entry) {
|
|
26828
26869
|
if (entry.status === "finished") {
|
|
26829
26870
|
const kosModel2 = KosCore.getInstance().modelManager.getModelById(key);
|
|
26830
26871
|
return { kosModel: kosModel2, model: kosModel2?.modelData };
|
|
26831
|
-
} else {
|
|
26832
|
-
throw entry.promise;
|
|
26833
26872
|
}
|
|
26834
|
-
|
|
26835
|
-
|
|
26836
|
-
|
|
26837
|
-
|
|
26838
|
-
},
|
|
26839
|
-
(error) => {
|
|
26840
|
-
cache$1.set(key, { status: "error", error });
|
|
26841
|
-
throw error;
|
|
26842
|
-
}
|
|
26843
|
-
);
|
|
26844
|
-
const entry = { status: "pending", promise };
|
|
26845
|
-
cache$1.set(key, entry);
|
|
26846
|
-
throw promise;
|
|
26873
|
+
if (entry.status === "error") {
|
|
26874
|
+
throw entry.error;
|
|
26875
|
+
}
|
|
26876
|
+
throw entry.promise;
|
|
26847
26877
|
}
|
|
26878
|
+
const promise = fetcher().then(
|
|
26879
|
+
() => {
|
|
26880
|
+
modelHookCache.set(key, { status: "finished", key });
|
|
26881
|
+
},
|
|
26882
|
+
(error) => {
|
|
26883
|
+
modelHookCache.set(key, { status: "error", error });
|
|
26884
|
+
throw error;
|
|
26885
|
+
}
|
|
26886
|
+
);
|
|
26887
|
+
modelHookCache.set(key, { status: "pending", promise });
|
|
26888
|
+
throw promise;
|
|
26848
26889
|
}
|
|
26849
26890
|
function useSuspenseData$1(key, fetcher) {
|
|
26850
26891
|
const data = fetchData$1(key, fetcher);
|
|
@@ -26935,7 +26976,7 @@ const useKosModel = (modelOptions) => {
|
|
|
26935
26976
|
if (destroyOnUnmount) {
|
|
26936
26977
|
const modelId2 = model.id;
|
|
26937
26978
|
destroyKosModel(model).then(() => {
|
|
26938
|
-
|
|
26979
|
+
clearModelHookCacheEntry(modelId2);
|
|
26939
26980
|
disposer?.();
|
|
26940
26981
|
});
|
|
26941
26982
|
}
|
|
@@ -26944,7 +26985,7 @@ const useKosModel = (modelOptions) => {
|
|
|
26944
26985
|
} else {
|
|
26945
26986
|
if (destroyOnUnmount && model) {
|
|
26946
26987
|
destroyKosModel(model).then(() => {
|
|
26947
|
-
|
|
26988
|
+
clearModelHookCacheEntry(modelId);
|
|
26948
26989
|
disposer?.();
|
|
26949
26990
|
});
|
|
26950
26991
|
}
|
|
@@ -29217,6 +29258,7 @@ export {
|
|
|
29217
29258
|
checkAppsStarted,
|
|
29218
29259
|
checkWildcardPattern,
|
|
29219
29260
|
clearAllServiceResponses,
|
|
29261
|
+
clearModelHookCacheEntry,
|
|
29220
29262
|
clearPath,
|
|
29221
29263
|
clearServiceResponse,
|
|
29222
29264
|
convert,
|
|
@@ -29375,6 +29417,7 @@ export {
|
|
|
29375
29417
|
mapUpdateDtoToConfigBeanModel,
|
|
29376
29418
|
modelEventTopicFactory,
|
|
29377
29419
|
modelFactory,
|
|
29420
|
+
modelHookCache,
|
|
29378
29421
|
modelTypeEventTopicFactory,
|
|
29379
29422
|
modifyConfigBean,
|
|
29380
29423
|
modifyFuture,
|