Skip to content

Activity

Overview

This module exports two composables:

  • useActivity(name, options) — sets up the state and configuration stores for a named activity and registers it as the current activity.
  • useCurrentActivity(options) — retrieves the current activity context from anywhere in the component tree without needing to know the activity name.

Causes the current activity to be automatically reset on unmount.

Usage

javascript
// In the activity component itself
import { useActivity } from '@kalisio/kdk/core.client'
const { CurrentActivityContext, setCurrentActivity, selectItem } = useActivity('myMap', { selection: true })

// In a child component
import { useCurrentActivity } from '@kalisio/kdk/core.client'
const { kActivity, kActivityName, CurrentActivityContext } = useCurrentActivity()

useActivity(name, options)

Parameters

ParameterTypeDefaultDescription
namestringUnique activity name. Used as the store namespace and to look up configuration in config[name].
options.selectionbooleantrueWhen true, also initialises a selection store for this activity (via useSelection).
options.stateObjectInitial state content for the activity state store.

Exposed

NameTypeDescription
CurrentActivityContextshallowReactive ObjectShared context object: { activity, name, state, config }. Mutated in place when the activity changes.
setCurrentActivity(activity)FunctionSets the given component instance as the current activity. Pass null to clear.
(selection)All values from useSelection(name) are merged in when options.selection is true.

Lifecycle

  • beforeUnmount: clears CurrentActivityContext properties and calls setCurrentActivity(null).

useCurrentActivity(options)

Parameters

ParameterTypeDefaultDescription
options.selectionbooleantrueWhen true, also retrieves the selection store from the current activity.

Exposed

NameTypeDescription
CurrentActivityContextshallowReactive ObjectThe shared context object (same reference as in useActivity).
CurrentActivityshallowRef<Object | null>The raw current activity component instance.
kActivityreadonly shallowRefRead-only alias for CurrentActivity.
kActivityNamereadonly Ref<string | null>Read-only alias for CurrentActivityContext.name.
(all from useActivity)When an activity is active, all values exposed by its useActivity call are merged in.