# Correct way to build components

**URL:** <https://meta.discourse.org/t/correct-way-to-build-components/55407>\
**Category:** Development\
**Created:** [1월 9, 2017, 1:28오후 UTC](https://meta.discourse.org/t/correct-way-to-build-components/55407 "2017-01-09T13:28:10Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![piratdavid](https://avatars.discourse-cdn.com/v4/letter/p/ba9def/32.png) [@piratdavid](https://meta.discourse.org/u/piratdavid)\
**Post date:** [1월 9, 2017, 1:28오후 UTC](https://meta.discourse.org/t/correct-way-to-build-components/55407/1 "2017-01-09T13:28:10Z")

</div>

Here’s the structure of a component that I’m presenting in a News feed plugin on a page that’s not tied to the forum part of Discourse. My question is: Am I doing it right?

A controller that creates the components model and stores it as a variable on itself.  
A model that fetches its own data with ajax on creation and start a subscription on the messagebus that is passed on from the constructor.  
A component that receives its model from the creation in markup. It cancels the subscription on willDestroyElement and reinitiates it on didInsertElement.  
A template representing the markup.

I’m not sure if this is the right way to go. Is it right to pass the model this way? Should a component have a model? Should the model fetch it’s own data? It is not as self contained as I would have thought a component should be. Should it even be implemented as a component?

Hope to get some clarity in this.

Thanks  
David

---

_[View the full topic](https://meta.discourse.org/t/correct-way-to-build-components/55407)._
