Files
docs/projects/slm-design/canons/examples/react/factory-composition.md
S.Gromov 89cc873c19
All checks were successful
CI/CD Pipeline / build (push) Successful in 44s
CI/CD Pipeline / docker (push) Successful in 1m17s
CI/CD Pipeline / deploy (push) Successful in 8s
docs: обновить архитектуру SLM compositions
- обновлена модель слоёв на app → compositions → business → infra → ui → shared
- добавлены правила composition modules и providers-сегмента
- обновлены правила монорепозитория для слоя compositions
- переписаны React-примеры под page-level композицию
- добавлен пример вариантов структуры compositions
2026-05-26 23:46:11 +03:00

2.1 KiB
Raw Blame History

title, description
title description
Композиция фабрик Пример композиции business-фабрик на уровне composition module в React-проекте

Композиция фабрик

Раздел показывает, как собрать API нескольких business-модулей в React composition module. Пример подходит для простой композиции, когда page composition сама является точкой использования доменов.

Идея

Композиция фабрик выполняется в модуле-потребителе на слое compositions: page, layout, screen, widget или другом composition module.

Business-модули не импортируют runtime-код друг друга напрямую, а cross-domain зависимости получают только через аргументы фабрик.

Структура page composition

compositions/pages/home/
├── home.page.tsx
└── index.ts

Сборка фабрик

Файл: compositions/pages/home/home.page.tsx.

import { customerFactory } from '@/business/customer'
import { orderFactory } from '@/business/order'

const customer = customerFactory()
const order = orderFactory({ customer })

const { useOrder, OrderCard } = order

export const HomePage = () => {
  const currentOrder = useOrder()

  return <OrderCard order={currentOrder} />
}

customerFactory создаётся первой, потому что orderFactory зависит от части API домена customer. Модуль order не импортирует customer в runtime — зависимость передаётся снаружи.

Публичный API page composition

Файл: compositions/pages/home/index.ts.

export { HomePage } from './home.page'

Page composition экспортирует только собственный публичный API. Собранные экземпляры business API остаются деталями реализации модуля.