Replace generateKeyed$ with a redesigned generateItems operator

And use it to clean up a number of code smells, fix some reactivity bugs, and avoid some resource leaks.
This commit is contained in:
Robin
2025-11-07 17:36:16 -05:00
parent 1f386a1d57
commit b4c17ed26d
18 changed files with 610 additions and 441 deletions

View File

@@ -97,7 +97,7 @@ test.skip("should always have our own user", () => {
expectObservable(dn$.pipe(map((e) => e.value))).toBe("a", {
a: new Map<string, string>([
["@local:example.com:DEVICE000", "@local:example.com"],
["@local:example.com", "@local:example.com"],
]),
});
});
@@ -130,9 +130,9 @@ test("should get displayName for users", () => {
expectObservable(dn$.pipe(map((e) => e.value))).toBe("a", {
a: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@alice:example.com:DEVICE1", "Alice"],
["@bob:example.com:DEVICE1", "Bob"],
// ["@local:example.com", "it's a me"],
["@alice:example.com", "Alice"],
["@bob:example.com", "Bob"],
]),
});
});
@@ -152,8 +152,8 @@ test("should use userId if no display name", () => {
expectObservable(dn$.pipe(map((e) => e.value))).toBe("a", {
a: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@no-name:foo.bar:D000", "@no-name:foo.bar"],
// ["@local:example.com", "it's a me"],
["@no-name:foo.bar", "@no-name:foo.bar"],
]),
});
});
@@ -179,12 +179,12 @@ test("should disambiguate users with same display name", () => {
expectObservable(dn$.pipe(map((e) => e.value))).toBe("a", {
a: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@bob:example.com:DEVICE1", "Bob (@bob:example.com)"],
["@bob:example.com:DEVICE2", "Bob (@bob:example.com)"],
["@bob:foo.bar:BOB000", "Bob (@bob:foo.bar)"],
["@carl:example.com:C000", "Carl (@carl:example.com)"],
["@evil:example.com:E000", "Carl (@evil:example.com)"],
// ["@local:example.com", "it's a me"],
["@bob:example.com", "Bob (@bob:example.com)"],
["@bob:example.com", "Bob (@bob:example.com)"],
["@bob:foo.bar", "Bob (@bob:foo.bar)"],
["@carl:example.com", "Carl (@carl:example.com)"],
["@evil:example.com", "Carl (@evil:example.com)"],
]),
});
});
@@ -208,13 +208,13 @@ test("should disambiguate when needed", () => {
expectObservable(dn$.pipe(map((e) => e.value))).toBe("ab", {
a: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@bob:example.com:DEVICE1", "Bob"],
// ["@local:example.com", "it's a me"],
["@bob:example.com", "Bob"],
]),
b: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@bob:example.com:DEVICE1", "Bob (@bob:example.com)"],
["@bob:foo.bar:BOB000", "Bob (@bob:foo.bar)"],
// ["@local:example.com", "it's a me"],
["@bob:example.com", "Bob (@bob:example.com)"],
["@bob:foo.bar", "Bob (@bob:foo.bar)"],
]),
});
});
@@ -238,13 +238,13 @@ test.skip("should keep disambiguated name when other leave", () => {
expectObservable(dn$.pipe(map((e) => e.value))).toBe("ab", {
a: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@bob:example.com:DEVICE1", "Bob (@bob:example.com)"],
["@bob:foo.bar:BOB000", "Bob (@bob:foo.bar)"],
// ["@local:example.com", "it's a me"],
["@bob:example.com", "Bob (@bob:example.com)"],
["@bob:foo.bar", "Bob (@bob:foo.bar)"],
]),
b: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@bob:example.com:DEVICE1", "Bob (@bob:example.com)"],
// ["@local:example.com", "it's a me"],
["@bob:example.com", "Bob (@bob:example.com)"],
]),
});
});
@@ -273,14 +273,14 @@ test("should disambiguate on name change", () => {
expectObservable(dn$.pipe(map((e) => e.value))).toBe("ab", {
a: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@bob:example.com:B000", "Bob"],
["@carl:example.com:C000", "Carl"],
// ["@local:example.com", "it's a me"],
["@bob:example.com", "Bob"],
["@carl:example.com", "Carl"],
]),
b: new Map<string, string>([
// ["@local:example.com:DEVICE000", "it's a me"],
["@bob:example.com:B000", "Bob (@bob:example.com)"],
["@carl:example.com:C000", "Bob (@carl:example.com)"],
// ["@local:example.com", "it's a me"],
["@bob:example.com", "Bob (@bob:example.com)"],
["@carl:example.com", "Bob (@carl:example.com)"],
]),
});
});