mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-27 04:03:00 +02:00
Do not use object constructors for names (#4149)
* Do not use object constructors for names Minification was selecting different class names for different instances of services, which was causing them not to sync properly. This was happening _only_ in production mode for some reason, perhaps due to minifying post chunking? * Add tests for additional synced properties
This commit is contained in:
parent
4d14508729
commit
d4a8e5829a
@ -8,9 +8,12 @@ describe("sessionSync decorator", () => {
|
||||
class TestClass {
|
||||
@sessionSync({ ctor: ctor, initializer: initializer })
|
||||
private testProperty = new BehaviorSubject("");
|
||||
@sessionSync({ ctor: ctor, initializer: initializer, initializeAs: "array" })
|
||||
private secondTestProperty = new BehaviorSubject("");
|
||||
|
||||
complete() {
|
||||
this.testProperty.complete();
|
||||
this.secondTestProperty.complete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,11 +22,40 @@ describe("sessionSync decorator", () => {
|
||||
expect((testClass as any).__syncedItemMetadata).toEqual([
|
||||
expect.objectContaining({
|
||||
propertyKey: "testProperty",
|
||||
sessionKey: "TestClass_testProperty",
|
||||
sessionKey: "testProperty_0",
|
||||
ctor: ctor,
|
||||
initializer: initializer,
|
||||
}),
|
||||
testClass.complete(),
|
||||
expect.objectContaining({
|
||||
propertyKey: "secondTestProperty",
|
||||
sessionKey: "secondTestProperty_1",
|
||||
ctor: ctor,
|
||||
initializer: initializer,
|
||||
initializeAs: "array",
|
||||
}),
|
||||
]);
|
||||
testClass.complete();
|
||||
});
|
||||
|
||||
class TestClass2 {
|
||||
@sessionSync({ ctor: ctor, initializer: initializer })
|
||||
private testProperty = new BehaviorSubject("");
|
||||
|
||||
complete() {
|
||||
this.testProperty.complete();
|
||||
}
|
||||
}
|
||||
|
||||
it("should maintain sessionKey index count for other test classes", () => {
|
||||
const testClass = new TestClass2();
|
||||
expect((testClass as any).__syncedItemMetadata).toEqual([
|
||||
expect.objectContaining({
|
||||
propertyKey: "testProperty",
|
||||
sessionKey: "testProperty_2",
|
||||
ctor: ctor,
|
||||
initializer: initializer,
|
||||
}),
|
||||
]);
|
||||
testClass.complete();
|
||||
});
|
||||
});
|
||||
|
@ -9,6 +9,9 @@ class BuildOptions<T, TJson = Jsonify<T>> {
|
||||
initializeAs?: InitializeOptions;
|
||||
}
|
||||
|
||||
// Used to ensure uniqueness for each synced observable
|
||||
let index = 0;
|
||||
|
||||
/**
|
||||
* A decorator used to indicate the BehaviorSubject should be synced for this browser session across all contexts.
|
||||
*
|
||||
@ -44,7 +47,7 @@ export function sessionSync<T>(buildOptions: BuildOptions<T>) {
|
||||
|
||||
p.__syncedItemMetadata.push({
|
||||
propertyKey,
|
||||
sessionKey: `${prototype.constructor.name}_${propertyKey}`,
|
||||
sessionKey: `${propertyKey}_${index++}`,
|
||||
ctor: buildOptions.ctor,
|
||||
initializer: buildOptions.initializer,
|
||||
initializeAs: buildOptions.initializeAs ?? "object",
|
||||
|
Loading…
Reference in New Issue
Block a user