2021-08-12 19:30:49 +00:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
class AttributeWithCacheKeyImpl {
|
|
|
|
|
constructor(attribute: Record<string, unknown>) {
|
|
|
|
|
Object.assign(this, attribute);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-20 20:00:56 +00:00
|
|
|
private key: string;
|
2021-08-12 19:30:49 +00:00
|
|
|
public get cacheKey(): string {
|
2023-11-20 20:00:56 +00:00
|
|
|
if (!this.key) {
|
|
|
|
|
this.key =
|
2021-08-12 19:30:49 +00:00
|
|
|
Object.getOwnPropertyNames(this).sort().map(name => `${(this as Record<string, unknown>)[name]}`).join(';');
|
|
|
|
|
}
|
2023-11-20 20:00:56 +00:00
|
|
|
return this.key;
|
2021-08-12 19:30:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface AttributeWithCacheKey {
|
|
|
|
|
readonly cacheKey: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const createAttributeWithCacheKey = <T extends Record<string, unknown>>(attribute: T): T&AttributeWithCacheKey =>
|
|
|
|
|
new AttributeWithCacheKeyImpl(attribute) as unknown as T & AttributeWithCacheKey;
|