연구 설문조사: Blockly 사용 경험을 알려주세요
설문조사 시작
이벤트
워크스페이스의 모든 변경사항은 이벤트를 트리거합니다. 이러한 이벤트는 각 변경사항의 전후 상태를 완전히 설명합니다.
이벤트 리슨
워크스페이스에는 이벤트 스트림을 수신 대기하는 데 사용할 수 있는 addChangeListener
및 removeChangeListener
메서드가 있습니다. 코드의 실시간 생성이 그 예입니다.
또 다른 예는 최대 차단 한도 데모입니다.
일반적으로 이 두 예시에서는 트리거 이벤트가 무엇인지 신경 쓰지 않습니다. 워크스페이스의 현재 상태만 확인합니다.
더 정교한 이벤트 리스너는 트리거 이벤트를 확인합니다. 다음 예에서는 사용자가 첫 번째 댓글을 작성하고 알림을 보낸 다음 더 이상 알림이 트리거되지 않도록 리슨을 중지하는 시점을 감지합니다.
function onFirstComment(event) {
if (event.type == Blockly.Events.BLOCK_CHANGE &&
event.element == 'comment' &&
!event.oldValue && event.newValue) {
alert('Congratulations on creating your first comment!')
workspace.removeChangeListener(onFirstComment);
}
}
workspace.addChangeListener(onFirstComment);
플라이아웃 내에서 발생하는 이벤트를 수신 대기하려면 플라이아웃의 워크스페이스에 리스너를 추가하면 됩니다.
var flyoutWorkspace = yourWorkspace.getFlyout().getWorkspace();
flyoutWorkspace.addChangeListener(onFirstComment);
블록에는 이벤트 스트림을 리슨하는 다른 메서드가 있습니다. 블록은 onchange
함수를 정의하거나 setOnChange를 사용하여 블록의 워크스페이스에 변경사항이 발생할 때마다 호출되는 함수를 설정할 수 있습니다.
이벤트 유형
개별 이벤트에 대한 자세한 내용은
참조 문서를 확인하세요.
데모
이벤트로 할 수 있는 멋진 작업의 예는 미러 데모를 확인하세요.
이 데모에는 이벤트를 사용하여 동기화되는 두 개의 Blockly 워크스페이스가 있습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-11-08(UTC)
[null,null,["최종 업데이트: 2024-11-08(UTC)"],[[["Every workspace change triggers an event detailing the before and after state."],["Workspaces offer methods (`addChangeListener`, `removeChangeListener`) to listen for these events."],["Events can be used for various purposes like real-time code generation or triggering actions based on specific changes (e.g., a new comment)."],["Blocks can also have individual change listeners using the `onchange` function or `setOnChange`."],["Comprehensive event details are available in the Blockly reference documentation."]]],["Workspace changes trigger events, describing the before and after states. Listeners can be added using `addChangeListener` and removed with `removeChangeListener`. Listeners can react to specific events, like the creation of a comment, or monitor all events. Flyout events can be monitored by adding a listener to the flyout's workspace. Blocks can use an `onchange` function to listen for changes in their workspace. There are several event types as described in the documentation.\n"]]