RAGS - v1.11.0
    Preparing search index...

    Class Variable<T>

    A reactive variable that holds a value and emits signals on change.

    Variables are the primary reactive primitive in AGS. They can optionally poll a command/function at intervals or listen to a subprocess for continuous updates.

    // Simple reactive variable
    const count = Variable(0);
    count.value = 5;

    // Poll a command every 5 seconds
    const time = Variable('', {
    poll: [5000, 'date'],
    });

    // Listen to a subprocess
    const workspaces = Variable('', {
    listen: ['hyprctl activeworkspace -j', JSON.parse],
    });

    Type Parameters

    • T

      The type of value held by the variable

    Hierarchy

    • Object
      • Variable

    Implements

    Index

    Accessors

    • get is_disposed(): boolean

      Whether the variable has been disposed.

      Returns boolean

    • get is_listening(): boolean

      Whether a listener subprocess is currently active.

      Returns boolean

    • get is_polling(): boolean

      Whether a poll loop is currently active.

      Returns boolean

    Constructors

    • Type Parameters

      • T

        The type of value held by the variable

      Parameters

      • value: T

        The initial value

      • options: Options<T> = {}

        Optional polling or listening configuration

      Returns Variable<T>

    Methods

    • Creates a Binding for a property on this variable.

      When called without arguments, binds to 'value' and preserves the variable's type parameter T as the binding's return type.

      Type Parameters

      • P extends "$signals" | "is_listening" | "is_polling" | "is_disposed" | "value"

      Returns Binding<Variable<T>, P, T>

      A Binding that can be used in widget constructors

    • Creates a Binding for a property on this variable.

      When called without arguments, binds to 'value' and preserves the variable's type parameter T as the binding's return type.

      Type Parameters

      • P extends "$signals" | "is_listening" | "is_polling" | "is_disposed" | "value"

      Parameters

      • Optionalprop: P

      Returns Binding<Variable<T>, P, Variable<T>[P]>

      A Binding that can be used in widget constructors

    • Connects a callback to a signal on this variable.

      Parameters

      • signal: string = 'notify::value'

        The signal name (defaults to 'notify::value')

      • callback: (self: this, ...args: any[]) => void

        The callback to invoke

      Returns number

      The connection ID

    • Sets the value, emitting notify::value and changed signals.

      Parameters

      • value: T

      Returns void

    • Starts listening to a subprocess if a listen configuration was provided.

      Returns void

    • Starts the poll loop if a poll configuration was provided.

      Returns void

    • Stops the active listener subprocess.

      Returns void

    Properties

    _autoSuspend: boolean = false
    _interval?: number
    _listen?: Listen<T>
    _poll?: Poll<T>
    _subprocess?: Subprocess | null
    _value: T
    _visibleConsumers: number = 0