Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Architecture advice - firing events to update views

$
0
0

Hello!

I'm working on my first major Titanium app and I'm using CommonJS modules. I'm looking for advice on the best way to handle the following scenario:

(Disclaimer: I'm sure there are star rating components in the marketplace, and that there may be other ways of accomplishing a star rating, but I have other elements that will have similar issues and the star rating is the easies one to explain.)

I have a star rating view that users can click to increment the rating by one. This consists of a wrapper view containing two labels. So, an item with a 3 star rating would display 2 "empty" stars and 3 "solid" stars. When a user taps anywhere on the container view, the rating count is incremented by one.

To achieve this, I've created a function in a CommonJS module called "getStarRatingView" which accepts an item id (to handle database lookups for values, etc). I have a section of the app where I list many items (name and tappable star rating). When you tap the name of the item, it goes to a detail view that also displays the tappable star rating. When I update one instance of the star rating view, I'd like to update the other instance (ideally, all other instances in my app).

My first thought was to use a custom application level event. Things get tricky with recursion here (which instance of the view was tapped, which instances should I update).

It's a situation where I wish I could fall back to my old jQuery crutch and use some kind of selector engine to find all instances of the view currently in the app, but I'm not aware of such a thing.

Any suggestions? Thanks!!


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>