How can I put a delay on the same subsequent action? - reactjs

Using redux-toolkit, rxjs, redux-observable
I want to add a 1-second delay between the same action if they are within a short period of time.
A naive example:
if you click a button that displays a pop-up 10 times really quickly, then I want to only show all ten pop-ups but only one pop-up for a second before showing the next pop-up.
let's say the button dispatches an action. is there a way to observe the stream of actions coming in and add a delay?

Related

Run a callback after mouse scrolling is done in C with Gtk

I'm working on a C application using Gtk for the GUI. We have custom slider widgets connected to the "mouse scrolled" event with a callback function. The problem is each scrolling increment will trigger the callback once, which updates a parameter and refreshes a computationaly-expensive rendering. So, when the user scrolls more than once, the GUI freezes until all scrolls are processed individually in sequence.
I want to have the multiple unit scrolling increments recorded as one flat increment, such that the expensive rendering is started only once the user is done scrolling, so we only record all increments until the scrolling is finished and then we update the parameter and refresh the rendering.
My first idea was to have the "mouse scrolled" callback emit some "update" signal and save :
the timestamp of the scroll event long t,
the number of scrolling increments int steps
Each new scrolling event would increment the steps counter and overwrite the timestamp.
Then, the "update" signal would be captured by a function that would wait for t + 0.5 s to actually save the slider value and trigger a new rendering. If the user performs a new scrolling during that time, the function would just keep waiting.
Is there a Gtk or C API to perform that kind of task ?

Best way to introduce repeated action to a Button descendant

I'd like derive a class from Button to add an initial delay and interval which shall be used as long as the button is touched for repeated action.
At first thought this seems to be simple enough but the method com.codename1.ui.Button.setState(int) cannot be overridden because it has package access only. Is that for a good reason?
I noticed, that Button calls actionPerformed on pointerReleased. My Button descendant should call actionPerformed repeatedly but not wen the parent container of the Button is beeing scrolled. This would hopefully just correspond with the Button state STATE_PRESSED, right?
If I understand correctly what you mean then I'd just start a timer on the pressed method and then repeatedly call super.pressed & super.released whenever the timer elapses.

How to allow/stop an event based on a condition like YES or NO?

I need to allow or stop an event from happening, based on a given condition such as a pop up box with options YES, NO and CANCEL.
I need to notify the user saying that there are unsaved data and if the user wishes to SAVE it, IGNORE it or CANCEL his current action(event such as Selection-change or Click).
I tried to use createInterceptor() function. But could not achieve the functionality.
Can anybody give me some suggestions with example? Basically I want to know how to stop an event.
Thanks..
Edited
I like the idea of using beforeXXX events. But I am still facing problems. As I mentioned, I need to ask the user if he wishes to save the unsaved data, which is a popup message box (With options YES, NO and CANCEL) that runs asynchronously. So by the time I get a reply, the event will have happened.
For ex. lets imagine a situation where, there is a page that displays a list of records in a grid with a pagination toolbar attached to it on the bottom(with a page size of 10 and total number pages is 10. So totally 100 records) on the left hand side. If you select a record in the list, the details are shown in a detail view on the right hand side.
Now,
I select third record in the list and make some changes to it in the detail view(form).
Without saving the record, I click on next page button on the Pagination toolbar.
It will show a confirm box from the beforeXXX event of Pagination toolbar, but the event will have happened anyway.
Here if the user clicks on CANCEL, I will have to restore the previous state which is already gone. Somehow I will have to go back and select the third record in the list of previous page.
So in order to resolve this problem, if I return false from my beforeXXX event, the next XXX event will be not be triggered.
But if the user clicks on YES or NO options I will have to trigger the event XXX manually which I am unable to do it for a selection-change event as of now.
Like this there can be many operations like list-filtering, searching, Ordering(A-Z/ Z-A), logout etc. For each of this operation I will have to write customised code which totally spoils the readability of the code.
So I was thinking if there is way to, somehow manually trigger the event XXX by holding the event object in beforeXXX...or is there any other way to restore the previous state.
Please give me suggestions....Thanks...
Many events have their "before-" counterpart, for example "beforeactivate". If you return false from this kind of the processing stops.
If not, or if your event does not have it's before- part, then you can use event object passed to all event handlers and call:
ev.stopEvent();
ev.stopPropagation();
return false;
at the end of your handler.

Dialog box closes slowly after clicking send button

In my webapp, I have a send dialogue box which sends the data to a selected email address. The issue is that the dialog box disappears after few seconds of clicking send button which makes the user click send button multiple times as a result of which same mail is sent multiple times.
What I think is that this can be a function of the speed of the DB (and probably the size of the data).
If it takes several second to receive confirmation then you must reflect that in the UI, by putting up a "wait" cursor, disabling the "Send" button, possibly dimming the dialog box etc. There's nothing wrong with taking a few seconds as long as you make sure the user is aware and cannot click Send a second time
Even if you expect the operation to be nearly instantaneous in most cases, you STILL must reflect the possibility of a delay in the UI. That's just a fundamental UI design principle.

WPF updating the UI with a certain delay

I have a slideshow application where i want to wait a certain amount of seconds, then show my front page, then wait again, then show next page, and so on. My problem is that when i use Thread.Sleep in between, the UI arent updated, it just sits there waiting and i only see my last control (after the full amount of time has passed (i.e all the sleeps). Any solutions for doing this?
Thread.Sleep(1000);
ChangeContent(new FrontPage());
Thread.Sleep(5000);
ChangeContent(new HtmlPage());
Pre WPF i would just use the Application.DoEvents.
Use a DispatcherTimer.

Resources