I'm making an quiz application, which consist of following domain model
Quiz => *Category => *Question => *Choice
with one-to-many relationship with all the models.
QuizStateService stores the fetched Quiz objects in an array, and have functions to toggle the currently shown quiz, category, questions and theirs choices. My current solution is to use normal object reference field for active Category in service, and bind it to the category property of the corresponding view in the top-level component template.
<category [cat]="quizStateService.activeCategory" />
This makes it possible to access all the others models deeper in the component hierarchy using Input binding and ngFors.
However, I would like to get each component's model straight from the service as an Observable, which components subscribes and updates it's model when Observable emits a new value. I think this design would be easier to extend or alter in the future, as component's state isn't tightly coupled to it's parents state anymore, but is externalized to a solid service layer.
So, how would I expose service layer data (plain objects) as Observables, which may emit new values when service logic is executed?
Aucun commentaire:
Enregistrer un commentaire