플러그인 개발에 대해 알아보고 있었는데, discourse translator와 같은 경우에서 findAncestorModel()을 통해 위젯 모델을 가져온 후, 진행하기 전에 결과가 존재하는지 확인하는 경우가 있습니다. 소스 코드에서도 이러한 패턴을 확인할 수 있으며, 예시는 다음과 같습니다:
_getTopicUrl() {
const post = this.findAncestorModel();
return post ? post.get("topic.url") : null;
},
하지만 조상 모델의 존재 여부를 확인하지 않는 경우도 있습니다. 몇 줄 아래의 코드처럼요:
const post = this.findAncestorModel();
const controller = this.register.lookup("controller:topic");
return post
.get("topic.postStream")
.filterUpwards(this.attrs.id)
.then(() => {
controller.updateQueryParams();
});
findAncestorModel의 결과 존재 여부는 얼마나 신뢰할 수 있을까요? 현재 있는 위젯에 따라 달라지는 건가요, 아니면 게시글 메뉴처럼 결과가 없는 상황이 거의 불가능해 보이는 경우에도 null 응답을 처리하는 것이 항상 좋은 관행인가요?