v2.1.0

useB24Helper Composable

Closure-based composable that owns a single B24HelperManager instance and exposes lifecycle helpers (init / destroy / Pull client glue).

Overview

useB24Helper() is a factory: each call returns a new closure with its own B24HelperManager slot and Pull-client state. It deduplicates init across re-renders and centralises destroy-on-unmount.

import { useB24Helper, LoadDataType } from '@bitrix24/b24jssdk'

const {
  initB24Helper,
  isInitB24Helper,
  destroyB24Helper,
  getB24Helper,
  usePullClient,
  useSubscribePullClient,
  startPullClient
} = useB24Helper()

Returned API

initB24Helper

initB24Helper(
  $b24: TypeB24,
  dataTypes?: LoadDataType[],
  requestId?: string
): Promise<B24HelperManager>

Creates a B24HelperManager (once per closure) and calls loadData(dataTypes, requestId). Subsequent invocations are no-ops — they return the same manager without re-fetching. dataTypes defaults to [LoadDataType.App, LoadDataType.Profile]; requestId defaults to 'helper-load-data'.

isInitB24Helper

isInitB24Helper(): boolean

Returns true after initB24Helper has resolved at least once.

destroyB24Helper

destroyB24Helper(): void

Calls destroy() on the underlying manager (closing the Pull client) and resets the closure flags so a new initB24Helper call will re-fetch from scratch.

getB24Helper

getB24Helper(): B24HelperManager

Returns the live manager. Throws 'B24HelperManager is not initialized. You need to call initB24Helper first.' when called before initB24Helper.

Pull client helpers

usePullClient(): void
useSubscribePullClient(callback: (message: TypePullMessage) => void, moduleId?: string): void
startPullClient(): void

Thin wrappers over the matching B24HelperManager methods. Order: usePullClientuseSubscribePullClient (one or more) → startPullClient. Calling useSubscribePullClient or startPullClient before usePullClient throws 'PullClient is not initialized. You need to call usePullClient first.'. See Pull client.

LoadDataType Enum

enum LoadDataType {
  App = 'app',
  Profile = 'profile',
  Currency = 'currency',
  AppOptions = 'appOptions',
  UserOptions = 'userOptions'
}

Each value drives one (or two for Currency) REST methods inside the batch — see the table on the B24HelperManager page.

Vue Example

<script setup lang="ts">
import { onMounted, onUnmounted } from 'vue'
import {
  initializeB24Frame,
  useB24Helper,
  LoadDataType,
  type B24Frame
} from '@bitrix24/b24jssdk'

const { initB24Helper, getB24Helper, destroyB24Helper } = useB24Helper()

let $b24: undefined | B24Frame

onMounted(async () => {
  $b24 = await initializeB24Frame()
  await initB24Helper($b24, [
    LoadDataType.Profile,
    LoadDataType.App,
    LoadDataType.Currency
  ])
  console.log('User:', getB24Helper().profileInfo.data)
})

onUnmounted(() => {
  destroyB24Helper()
  $b24?.destroy()
})
</script>