From e53bd36bdfee02be4652aa0eacf625fced1b182e Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Thu, 18 Jan 2024 14:30:28 -0500 Subject: [PATCH] Make cid a function for clarity --- src/index.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 07b7a65..47ad2ac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -250,7 +250,7 @@ function compose( ) { for (const { selector, style, isUnique } of stylesList) { const key = interpolate(selector, name); - const item = new Style(style, isUnique ? (++uniqueId).toString(36) : id); + const item = new Style(style, isUnique ? String(++uniqueId) : id); item.add(new Selector(key)); cache.add(item); } @@ -286,7 +286,7 @@ export interface Changes { */ export interface Container { /** Unique identifier for the cache, used for merging styles. */ - cid: string; + cid(): string; clone(): T; getStyles(): string; } @@ -304,7 +304,7 @@ export class Cache> { constructor(public changes?: Changes) {} add(style: T): void { - const id = style.cid; + const id = style.cid(); const count = this.counters[id] || 0; this.counters[id] = count + 1; @@ -316,7 +316,7 @@ export class Cache> { this.changeId++; if (this.changes) this.changes.add(item, index); } else if (style instanceof Cache) { - const index = this.children.findIndex((x) => x.cid === id); + const index = this.children.findIndex((x) => x.cid() === id); const item = this.children[index] as T & Cache; const prevChangeId = item.changeId; @@ -331,13 +331,13 @@ export class Cache> { } remove(style: T): void { - const id = style.cid; + const id = style.cid(); const count = this.counters[id]; if (count) { this.counters[id] = count - 1; - const index = this.children.findIndex((x) => x.cid === id); + const index = this.children.findIndex((x) => x.cid() === id); if (count === 1) { const item = this.children[index]; @@ -378,7 +378,7 @@ export class Cache> { export class Selector implements Container { constructor(public selector: string) {} - get cid() { + cid() { return this.selector; } @@ -402,7 +402,7 @@ export class Style extends Cache implements Container