Skip to content

Coordinator API

startCoordinator()

퍼널 및 규칙 정의로 coordinator를 초기화합니다.

typescript
const coordinator = startCoordinator({
  funnels: [...],
  nudgeRules: [...],
  runner: { run: ... },
  cooldownStorage,
  exposureStorage,
  getUserPersonalTier: (userId) => 'free' | 'pro',
});

파라미터

파라미터필수설명
funnels퍼널 정의 배열
nudgeRules규칙 정의 배열
runner액션 실행 핸들러
cooldownStorage쿨다운 영속성
exposureStorage노출 로그 영속성
getUserPersonalTier아니오사용자 등급 resolver 함수

사용법

typescript
const coordinator = startCoordinator({
  funnels: [paywallFunnel],
  nudgeRules: [paywallRule],
  runner: {
    run: async (action) => {
      if (action.type === 'paywall') {
        showPaywall(action.data);
      }
    },
  },
  cooldownStorage: new NudgeCooldownStorage({ storage: localStorage }),
  exposureStorage: new NudgeExposureLogStorage({ storage: localStorage }),
  getUserPersonalTier: (userId) => getUserTier(userId),
});

메서드

typescript
coordinator.cleanup();

Coordinator를 중지하고 구독을 정리합니다.

모범 사례

한 번만 초기화: 애플리케이션 시작 시 coordinator를 한 번만 생성합니다.

  • React: 빈 의존성 배열로 useEffect 내부에서
  • React Native: 빈 의존성 배열로 useEffect 내부에서
  • Vanilla JS: 애플리케이션 진입점에서

중복 방지: 여러 coordinator 인스턴스는 중복 액션 실행을 유발할 수 있습니다.

다음 단계

Released under the MIT License.