Skip to content

@jimka/typescript-ui / core / StyleRule

Class: StyleRule

Defined in: src/typescript/lib/core/StyleTarget.ts:128

Deferred-write buffer that materialises into a per-component CSSStyleRule the first time StyleRule.ensure is called.

Remarks

The rule factory is invoked lazily so detached construction incurs no stylesheet insertion. Once materialised, the rule object is stable for the lifetime of this StyleRule.

Inherited StyleTarget.set queues writes into a dirty bag while the target is null and writes through once ensure() has materialised the rule. Owners that need the rule on the stylesheet at first render (rather than at first write) register the rule via Component's registerStyleRule, which calls ensure() from applyStyle and flushes the dirty bag onto the live CSSStyleRule.

Extends

Constructors

new StyleRule()

ts
new StyleRule(factory: () => CSSStyleRule): StyleRule

Defined in: src/typescript/lib/core/StyleTarget.ts:131

Parameters

factory

() => CSSStyleRule

Returns

StyleRule

Overrides

StyleTarget.constructor

Methods

ensure()

ts
ensure(): CSSStyleRule

Defined in: src/typescript/lib/core/StyleTarget.ts:140

Materialises the underlying CSSStyleRule on first access and returns it. Pending dirty entries are flushed in the same call.

Returns

CSSStyleRule


flush()

ts
flush(): void

Defined in: src/typescript/lib/core/StyleTarget.ts:74

Drains the dirty bag onto the live target. No-op when the target is not yet attached — the dirty entries stay queued for the next flush after materialize.

Returns

void

Inherited from

StyleTarget.flush


isMaterialized()

ts
isMaterialized(): boolean

Defined in: src/typescript/lib/core/StyleTarget.ts:85

Returns whether the underlying target has been materialised.

Returns

boolean

Inherited from

StyleTarget.isMaterialized


queue()

ts
queue(key: string, value: null | string): void

Defined in: src/typescript/lib/core/StyleTarget.ts:56

Writes a single style property into the dirty bag without flushing, even when the target is already attached. Callers that own their own batching gate (e.g. autoCommitStyle = false) use this to accumulate writes that StyleTarget.flush will drain later.

Parameters

key

string

The CSS property name (camelCase).

value

The value to set, or null to remove the property.

null | string

Returns

void

Inherited from

StyleTarget.queue


queueMany()

ts
queueMany(values: Record<string, null | string>): void

Defined in: src/typescript/lib/core/StyleTarget.ts:65

Bulk variant of StyleTarget.queue.

Parameters

values

Record<string, null | string>

Camel-cased property keys mapped to string values (or null to clear).

Returns

void

Inherited from

StyleTarget.queueMany


set()

ts
set(key: string, value: null | string): void

Defined in: src/typescript/lib/core/StyleTarget.ts:30

Writes a single style property. Flushes immediately when the target is attached; otherwise queues the entry into the dirty bag.

Parameters

key

string

The CSS property name (camelCase).

value

The value to set, or null to remove the property.

null | string

Returns

void

Inherited from

StyleTarget.set


setMany()

ts
setMany(values: Record<string, null | string>): void

Defined in: src/typescript/lib/core/StyleTarget.ts:43

Bulk variant of StyleTarget.set.

Parameters

values

Record<string, null | string>

Camel-cased property keys mapped to string values (or null to clear).

Returns

void

Inherited from

StyleTarget.setMany