logologo
시작
가이드
개발
플러그인
API
홈
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
시작
가이드
개발
플러그인
API
홈
logologo
RunJS 개요
모듈 가져오기
컨테이너 내 렌더링

전역 변수

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.notification
Next Pagectx.on()
AI 번역 알림

이 문서는 AI에 의해 번역되었습니다. 정확한 정보는 영어 버전을 참조하세요.

#ctx.off()

ctx.on(eventName, handler)를 통해 등록된 이벤트 리스너를 제거합니다. 주로 ctx.on과 함께 사용되며, 적절한 시점에 구독을 취소하여 메모리 누수나 중복 트리거를 방지합니다.

#사용 사례

시나리오설명
React useEffect 정리(Cleanup)useEffect의 cleanup 함수에서 호출하여, 컴포넌트가 언마운트될 때 리스너를 제거합니다.
JSField / JSEditableField필드 양방향 바인딩 시, js-field:value-change에 대한 구독을 취소합니다.
resource 관련ctx.resource.on을 통해 등록된 refresh, saved 등의 리스너 구독을 취소합니다.

#타입 정의

off(eventName: string, handler: (event?: any) => void): void;

#예제

#React useEffect에서 쌍으로 사용

React.useEffect(() => {
  const handler = (ev) => setValue(ev?.detail ?? '');
  ctx.on('js-field:value-change', handler);
  return () => ctx.off('js-field:value-change', handler);
}, []);

#리소스 이벤트 구독 취소

const handler = () => { /* ... */ };
ctx.resource?.on('refresh', handler);
// 적절한 시점에 호출
ctx.resource?.off('refresh', handler);

#주의 사항

  1. handler 참조 일치: ctx.off 호출 시 전달하는 handler는 ctx.on 호출 시와 동일한 참조여야 합니다. 그렇지 않으면 올바르게 제거되지 않습니다.
  2. 적시 정리: 메모리 누수를 방지하기 위해 컴포넌트가 언마운트되거나 context가 파괴되기 전에 ctx.off를 호출하십시오.

#관련 문서

  • ctx.on - 이벤트 구독
  • ctx.resource - 리소스 인스턴스 및 해당 on/off 메서드