Skip to content
ts
import { field } from '@trail-run/core/reactive/storage-resource';

Function: field()

Call Signature

ts
function field(type): PropertyDecorator;

Defined in: src/reactive/storage-resource.ts:81

Decorator which marks a property as a field on a LocalResource or SessionResource

The field's value will be initialized from the persisted resource data if available, falling back to the property's default value otherwise.

Fields can be of any type that is serializable to and restorable from JSON, but complex types (like objects or arrays) should be handled with care to avoid unintended mutations or reactivity issues.

By default, fields are persisted in the storage type defined by the resource decorator (@LocalResource or @SessionResource). However, you can override this behavior by passing 'local' or 'session' as an argument to the decorator.


Example:

ts
@LocalResource('user-settings')
class UserSettings {
  @field
  theme: 'light' | 'dark' = 'light';

  @field('session')
  sessionToken: string | null = null;
}

Parameters

type

"local" | "session"

Returns

PropertyDecorator

Call Signature

ts
function field(
   target, 
   key, 
   descriptor?): void;

Defined in: src/reactive/storage-resource.ts:82

Decorator which marks a property as a field on a LocalResource or SessionResource

The field's value will be initialized from the persisted resource data if available, falling back to the property's default value otherwise.

Fields can be of any type that is serializable to and restorable from JSON, but complex types (like objects or arrays) should be handled with care to avoid unintended mutations or reactivity issues.

By default, fields are persisted in the storage type defined by the resource decorator (@LocalResource or @SessionResource). However, you can override this behavior by passing 'local' or 'session' as an argument to the decorator.


Example:

ts
@LocalResource('user-settings')
class UserSettings {
  @field
  theme: 'light' | 'dark' = 'light';

  @field('session')
  sessionToken: string | null = null;
}

Parameters

target

object

key

string

descriptor?

PropertyDescriptor

Returns

void

Released under the MIT License.