Skip to content

$store – Reactive Store API

Provides reactive access to any part of the application state and controlled mutation methods via a Redux-based backend.

ts
const { $store } = usePluginApi()

🧠 Core Concept

  • $store.get(...) is the foundation

  • Internally:

    • Subscribes to an observable
    • Wraps the result in a Vue ref
  • All getters return live reactive state

👉 This allows you to access any part of the store with automatic updates.


🧩 Application State Access

ts
const ui = $store.get(["ui"])
const widgets = $store.get(["widgets"])
const widget = $store.get(["widgets", widgetId])
  • pathArray maps directly to the global state tree
  • Returns a reactive ref

📥 Core Getter

get(pathArray, filter?)

ts
const state = $store.get(["queries", actionId])
  • Fully dynamic access to nested state
  • Reactive
  • Foundation for all other getters

📥 Specialized Getters

getWidgetState(widgetId?)

ts
const widgetState = $store.getWidgetState()

Resolves to:

ts
["widgets", widgetId]

getUiState()

ts
const uiState = $store.getUiState()

Resolves to:

ts
["ui"]

getQueryState(actionId)

ts
const queryState = $store.getQueryState(actionId)

Resolves to:

ts
["queries", actionId]

🔎 Query Action IDs

Query/action IDs follow this format:

plugin-<pluginKey>-<entity>-<action>-<uniqueId>

Example:

plugin-pacifico__example-todo-116-todo-getAll-sD9o

These IDs are:

  • Generated per query instance
  • Used as keys in:
ts
applicationState.queries[actionId]

getSiblingWidgetStates()

Returns reactive states of related widgets.


hasChanges(stateA, stateB)

ts
const changed = $store.hasChanges(originalState, currentState)
  • Requires two arguments

  • Returns true if differences are detected

  • Useful for:

    • dirty checks
    • save indicators
    • form comparisons

⚠️ getQueryData(actionId)

  • Not implemented

📤 Mutations

All mutations:

  • Dispatch Redux actions
  • Trigger reactive updates

setUiState(payload)

ts
$store.setUiState({ navigationOpen: true })

setWidgetState(payload, widgetId?)

ts
$store.setWidgetState({ foo: "bar" })
  • Full override

updateWidgetState(payload, widgetId?)

ts
$store.updateWidgetState({ count: 1 })
  • Merge update

updateConfig(payload, widgetId?)

ts
$store.updateConfig({ theme: "dark" })

updatePublic(payload, widgetId?)

Updates:

ts
widgets[widgetId].public

publishWorkingState(payload, widgetId?)

Updates:

ts
widgets[widgetId].workingState

updateDataItem(uuid, payload, override?)

ts
$store.updateDataItem("uuid-123", { name: "Updated" })

Targets:

ts
applicationState.data[uuid]

🔁 Reactivity Example

ts
const uiState = $store.getUiState()

$store.setUiState({ navigationOpen: true })

// uiState.value.navigationOpen updates automatically

⚖️ Mental Model

ConceptDescription
$store.getreactive selector (core primitive)
Query IDsunique keys for query instances
MutationsRedux dispatch → reactive updates
hasChangesexplicit state comparison utility

🧠 Key Takeaways

  • $store.get() lets you access any nested state reactively
  • Query states are indexed by generated action IDs
  • hasChanges(a, b) is a manual comparison tool, not reactive
  • Mutations propagate automatically to all consumers