javascript - Design pattern for persisting model and view across routes -
let's have search form @ /search queryview representing search form. when user submits query, route /results , add resultview results, keeping queryview in case user wants new search.
then, if user navigates directly /results, have create both queryview , resultsview in route function. problem i'd behavior in /search , /results routes same, have remember make changes in both places.
an alternative trigger route /results when user submits, destroy existing queryview , create new queryview , resultview. works, destroying , recreating queryview causes annoyances in case.
are there standard design patterns persist views across routes, without having code create view in 2 places?
you can put shared behavior in method of router, have both routes call method.
to cache queryview can make property of router. inside both /search , /results routes, like:
this.queryview = this.queryview || new queryview(); this.queryview.dowhatever();
Comments
Post a Comment