기본 콘텐츠로 건너뛰기

라벨이 mutation인 게시물 표시

vulcanJS - 부록 Appendix A. Mutation (delete) 보강

Posts를 만들면서 약간 아쉬웠던 부분은 Delete 부분에 대해서 너무 SmartForm에 의지하여 간단하게 넘어가긴 했다. showRemove={true} 옵션을 통해 한줄 찍 긋고 Delete라고 나오는 부분을 클릭하는 것도 좋지만 목록에서 지우거나 상세 보기에서 지울 일도 분명 있을 것이다. 역시나 이것도 목록(ex. withList)을 가져올 때 처럼 HoC(Higher-Order Component)를 사용한다. http://docs.vulcanjs.org/mutations.html#Remove-Mutation  부분을 참조하자. 이번에 구현할 것은 목록마다 remove 버튼을 달고 버튼을 누르면 이벤트를 받아 삭제하도록 구현해보자. import { registerComponent, withList, withRemove } from 'meteor/vulcan:core'; 먼저 해야할 것은 withRemove를 import에 추가하는 것이다. 그러면 withRemove를 registerComponent시 사용할 수 있다. withList와 함께 withRemove도 추가하자. registerComponent('PostsListComponent', PostsListComponent, [   withList, {     collection: Posts   }], [   withRemove, {     collection: Posts   } ]); withRemove도 withList와 동일하게 collection만 지정하면 된다. 준비는 다 되었다. withRemove를 붙여서 this.props는 removeMutation을 갖게 되었다. removeMutation의 사용법은 다음과 같다. this.props.removeMutation({   documentId: documentId }).then(...