From bce557cc2dc767628bed6aac87301a1be7c5431b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Tue, 4 Nov 2025 05:03:50 +0800 Subject: init commit --- .../src/foundation/json-parsing/derived-data.js | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 node_modules/@jet-app/app-store/tmp/src/foundation/json-parsing/derived-data.js (limited to 'node_modules/@jet-app/app-store/tmp/src/foundation/json-parsing/derived-data.js') diff --git a/node_modules/@jet-app/app-store/tmp/src/foundation/json-parsing/derived-data.js b/node_modules/@jet-app/app-store/tmp/src/foundation/json-parsing/derived-data.js new file mode 100644 index 0000000..fdf1f4e --- /dev/null +++ b/node_modules/@jet-app/app-store/tmp/src/foundation/json-parsing/derived-data.js @@ -0,0 +1,37 @@ +import * as validation from "@jet/environment/json/validation"; +import * as serverData from "./server-data"; +const DERIVED_CACHE_KEY = "_jet-internal:derived-data"; +export function value(data, key, generator) { + if (!data) { + return null; + } + return validation.context(key, () => { + let computedDataStore = data[DERIVED_CACHE_KEY]; + let returnValue = null; + if (!computedDataStore) { + computedDataStore = {}; + data[DERIVED_CACHE_KEY] = computedDataStore; + returnValue = generateValue(computedDataStore, key, generator); + } + else { + returnValue = serverData.traverse(computedDataStore, key); + if (!returnValue) { + returnValue = generateValue(computedDataStore, key, generator); + } + } + return returnValue; + }); +} +/** + * Computes an unknown value and saves it back into computedDataStore + * @param {JSONData} computedDataStore The dictionary in which to store the data + * @param {string} key The key to store it with + * @param {() => T} generator A function that will generate the value + * @returns {T} The value that was generated + */ +function generateValue(computedDataStore, key, generator) { + const generatedValue = generator(); + computedDataStore[key] = generatedValue; + return generatedValue; +} +//# sourceMappingURL=derived-data.js.map \ No newline at end of file -- cgit v1.2.3