Skip to content

Task profiles

Task profile выбирает schema или compiled recipe для задачи. Это основной способ рисовать разные статусы задач.

ts
const options = {
  profiles: {
    tasks: {
      by: 'status',
      default: 'active',
    },
  },
}

const taskProfiles = {
  defaultProfileId: 'active',
  profiles: {
    active: { schema: task => [/* NovaSchema */] },
  },
}

options.profiles.tasks.by выбирает id объявленного task profile. Значение может быть именем поля задачи или функцией. Порядок выбора единый: by(task), затем task.profile, task.kind, default.

Исполняемый примерTimeline: task profileВизуальные профили задач.
import { Nova, NovaNode, type NovaSchema } from '@endge/nova'

// Документационный сценарий: timeline-chart-task-profile
class ExampleNode extends NovaNode<Record<string, Event>> {
  render(): void {
    const schema: NovaSchema = [
      {
        type: 'rect',
        x: 24,
        y: 24,
        width: this.width - 48,
        height: this.height - 48,
        styles: { background: '#0d2745' },
      },
      {
        type: 'text',
        x: 44,
        y: 44,
        width: this.width - 88,
        height: 32,
        text: 'Timeline: task profile',
        styles: { color: '#e8f5ff' },
      },
    ]

    this.renderer.schema(schema)
    this.setRenderBoundsFromSchema(schema)
  }
}

export function mountExample(canvas: HTMLCanvasElement) {
  const app = Nova.createApp({
    target: canvas,
    size: { width: canvas.clientWidth, height: canvas.clientHeight, maxDpr: 2 },
    scheduler: { loop: false },
  })
  const surface = app.surface({ id: 'airport-layers' })
  surface.createNode(ExampleNode)

  return () => app.destroy()
}

Рекомендация

Держите profile resolver быстрым и детерминированным. Не делайте сетевые запросы и тяжелые вычисления из template path.