Update the UI in several places in the app [closed] - mobile

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
You're writing a music editing app. Once a composition is done, the app encodes it (asynchronously) into a speciļ¬ed audio format (.mp3 or .ogg). When the encoding is complete, you'd like to update the UI in several places in the app. Which of the following approaches to this problem makes the most sense?
Select the correct answer:
A. We can simply have the encoding system take a list of UI elements as parameters. When the encoding is done, it can tell the UI elements to update themselves.
B. A spin lock is a good way to do this. The UI code can enter a spin lock, continually checking if the encoding is done. When it is, it can update the UI and exit the lock. As long as the spin lock is not on the main thread, this will work well.
C. This is a perfect place for a factory method. The encoder will be the factory. When it is done with its fabrication (encoding the audio). the assembly line will take it to the UI elements, which can update the UI. before passing the composition further along the chain.
D. The important thing here is that we separate the UI update from the actual encoding logic. The encoding system should not know about UI. A good way to do this is a broadcast event. The encoding system can broadcast an event when a song is encoded. The UI code can listen for this event. and update the UI when it sees it.

I would say option D is the best choice. It would never let the app freeze. This is similar to event driven programming, on which most GUI apps are based.

Related

Understanding event driven architecture and state management in applications [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Hello guys I have a question regarding state management in applications centered around events.
Let us say take a scenario in which a some one posts a tweet on twitter, so this tweet should be visible to the users in real time. So things like posting a tweet or typing a comment etc are all real time events; where as fetching data from the server on the click of a button are all Restful in nature. Real-time communication can be achieved by using either web-sockets or server-sent-events. Now the question naturally that comes in the mind is How do we manage the data (state management) for rest as well as real time communication?
Restful resources are generally fetched as a bundle of information, but server sent event or websocket send it as a packet of information, by packet what i mean is data related to the single tweet. If we were to show a list of all tweets to the user we need to update the state to previously received tweets and incoming tweets but state management here becomes very hard.
I have looked at some solutions like RxJs which typically involves observables, and redux-saga which deals with generators. So can you share your experiences and insights to managing real time data and restful data.
End goal is how to manage rest and real time data in a live feed. Please feel free to correct me for any technical inaccuracies and/ suggestions. Thank you

Designing Server Side Timer/Countdown for a Quiz App [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am building a quiz app with Ionic React. I want to implement some kind of quiz timer/countdown feature to limit time spent on every question. The catch is, if I implement a countdown function on client side or Front-end, I'm afraid that folks could tamper with the script and cheat by manipulating the timer to their advantage.
Therefore, I think the only way to prevent this is to implement the timer/countdown feature server side. However, I do not know the right way to go about this... Wouldn't a countdown function blocks the server? Or is there some other way that I do not know?
There are two ways to handle this:
http:
You can run a timer at frontend. Notify the backend with start / end timestamp of each question to calculate the duration taken for each question. If the duration falls within the allowed range, you are good to proceed. Here, frontend is your source of truth but you are validating it at the backend.
websocket:
Or you can implement a websocket to communicate in real time with the backend. In this case, you can run the timer at backend and show its progress at frontend in realtime. Backend will be your single source of truth.
You can check this post too.

What is the best way ( performance wise ) to animate numbers? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
In my angular.js app i'm using this directive:
https://github.com/sparkalow/angular-count-to
Which works great on the web.
When i compile it for phonegap, it's really really slow.
But what other way i have to animate a number from 0 to 200 (for example), in two secods, without hurting the performance of my app?
The directive uses $timeout, as is the suggested way to get setTimeout functionality in Angular. It's likely doing this for one of the following reasons, though there are others too:
Easy to inject a mock for testing
Assumes that each step should allow other components to update
It's the "Angular Way"
I don't believe #2 is actually a big concern since it doesn't expose the value or update anything on the scope anyway, and does standard HTML textContent manipulation.
Regardless, the point is that $timeout does a setTimeout as well as a $digest (allowing Angular to update other components). The extra digest cycles are likely the slow part, and every Angular developer should read up on them as they're central to Angular's design (hint: go read up on these now). As such, taking the original library, replacing the $timeout with a setTimeout call (and, optionally, a manual digest trigger when it finishes, in the if (step >= steps) block) should speed it up.
Be careful about these sorts of changes, though - $timeout is typically the correct way to go.

How do I create a multiform GTK App [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hi I have been playing around with C and Gtk trying to learn a thing or two
Now wondering how do I create an application that has more then one form.
Do I just clear the window out or do I create new windows every time I want to have another form or view.
and does anyone know a good place to learn this type of thing?
I assume your goal is to use one window but change (large parts of) the window contents at times?
The widget you are looking for is GtkStack, which is a container that will only show one of its children at a time. You can use a Stack with user visible controls (StackSwitcher) or from your own code.
The Stack was only added in 3.10, so in earlier GTK+ versions you'll need to do the work yourself: Add your "forms" as children of a Box and make sure only one child is shown at a time.
does anyone know a good place to learn this type of thing?
To find out what kind of widgets you have at your disposal, I suggest reading the fine manual: https://developer.gnome.org/gtk3/stable/.

AngularJS best approach: data driven or event driven? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
AngularJS is famous of the '3d': data binding, dependency injection and directives. As data binding is such a nature of angularJS application, I always assume data-driven is the best approach when making decision on how the app works.
For example, if I want to respond to some property updates, I will $watch on that property and write call back functions for it. And if I can use angularJS properly, there is no $apply required and the two way data binding will automatically do the magic with the great digest cycles.
However, in jQuery or many other JavaScript libraries, event-driven seems to be so common that people always think this is how client side should work. Event-driven approach in angularJS, on the other hand, means I need to $emit or $broadcast events across directives/controllers to throw events here and there. This is somehow different to the data-driven approach.
My idea is event-driven makes the whole application hard to debug, understand and maintain. The only reason I use it is because it's easy to pass data across scopes, when the nested scopes themselves are too complicated to do so.
Any idea on this? When should we stick to data-driven and when should we use event driven? What is the best approach in general?

Resources