Skip to content

Commit 054e61a

Browse files
fix: update version to 2.1.3-beta and enhance SharedValuesManager with unique ID for instances
1 parent 8cea776 commit 054e61a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-shared-states",
3-
"version": "2.1.2",
3+
"version": "2.1.3-beta",
44
"type": "module",
55
"description": "Global state made as simple as useState, with zero config, built-in async caching, and automatic scoping.",
66
"keywords": [

src/SharedValuesManager.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ function getManager<T>(instanceKey: string, defaultValue: () => T = () => null a
1919

2020
export class SharedValuesManager<T> {
2121
data = new Map<string, SharedValue<T>>();
22-
23-
static INSTANCES = new Map<string, SharedValuesManager<any>>();
22+
private readonly _uniqueId: string;
2423

2524
constructor(protected defaultValue: () => T = () => null as T) {
25+
this._uniqueId = random();
26+
}
27+
28+
/**
29+
* @internal
30+
*/
31+
__get__uniqueId() {
32+
return this._uniqueId;
2633
}
2734

2835
static getInstance<T>(instanceKey: string, defaultValue: () => T = () => null as T): SharedValuesManager<T> {
@@ -156,7 +163,10 @@ export class SharedValuesManager<T> {
156163
}
157164

158165
export class SharedValuesApi<T> {
159-
constructor(protected sharedData: SharedValuesManager<T>) {}
166+
private readonly _uniqueId: string;
167+
constructor(protected sharedData: SharedValuesManager<T>) {
168+
this._uniqueId = random();
169+
}
160170

161171
private _get(key: string | SharedCreated, scopeName?: Prefix): { value: T, key: string, prefix: Prefix } {
162172
let keyStr: string;
@@ -181,6 +191,13 @@ export class SharedValuesApi<T> {
181191
};
182192
}
183193

194+
__log_instance_id() {
195+
return {
196+
apiId: this._uniqueId,
197+
managerId: this.sharedData.__get__uniqueId()
198+
}
199+
}
200+
184201
get(key: string, scopeName?: Prefix): T;
185202
get(sharedCreated: SharedCreated): T;
186203
get(key: string | SharedCreated, scopeName?: Prefix): T {

0 commit comments

Comments
 (0)