I have developed an web app using angular which connects with spotify and enables customers in my bar to add songs to the current playlist.
To do so I am calling the spotify API to get the current track, where i start a timeout using the time left of the currently playing song. Once this ends, I call the method again, as well as calling a request to get the playlist.
Currently using this method, it will make a few requests every few minutes.
To make it more accurate and update more readily, I want to make this timeout every ten seconds.Is this bad practice, and will it slow the app down or is this recommended?
if it is requesting more than one every time probably you need to make a little research about bubbling.
Shortly; probably your method is connected to a button and when the user clicked it, button calls the method. And also somewhere in your code you calling that method again (probably in a parent form element). when you click on a button that is inside a form, you also click to that form too so it calls both methods of form and button. In your case both of the same function so your method runs two times.
Related
May i get some help on the below points where i am using app-script to develop a gmail add-on:
How can we refresh gmail add-on with back ground process?
=> Here is my case, I need to display card with multiple sections which is the process of hitting multiple apis to fetch data and to display the card. For this initially we will show a card with minimal information to the user once i get information from api, i need to update the basic cards with complete information.
How can we trigger a function on every mail thread open?
=> Currently it works once for a mail, here as explained above point need to refresh a card once we fetch the data. If not, user will be seeing same basic information card every time he opens the mail.
From above mentioned issues for point one we are trying to get solution where we can hit service for certain interval of time to check data availability and if data exists then fetch data and update cards, i mean to say need a setTimeout function kind of thing, unfortunately we did'nt found this in app script and We found sleep/waitLock functions in app-script, but my services may take little time to fetch data as it connects though multiple services so we cant make the user to wait until the whole process is to be completed. So that we will show a card with basic information required then after need to auto refresh the cards once we fetch the data. we tried of keeping refresh button for the user to click and fetch the updated data but here we are losing user experience, trying for auto refresh with out user interference to get updated information.
Need a process / solution where we can auto refresh the card with out user interference after the data available at our end instead of making user to wait until the process to be completed.
Earliest reply will be more helpful for us.
Thanks.
If a data status on a third-party backend changes as the result of a user interaction with your add-on UI, it is recommended that the add-on set a 'state changed' bit to true so that any existing client side cache is cleared. See the ActionResponseBuilder.setStateChanged() method description for additional details.
The card-based interface in Gmail Addons is an Apps Script Service.
You can interlink it with other Apps Script services as well as implement API calls - everything within the same Apps Script file.
Gmail Addons contents automatically update every time the user opens a different e-mail or refreshes his browser.
Within your Apps Script code you can install time-driven triggers to run the data availability check with a customized frequency.
Consider to install for your users an Auto Refresh extension if you do not want them to refresh the card themselves.
I'm trying to use webhooks to get notifications for changes in a user's Box account. One thing I don't see is an option to get a webhook notification when an item is renamed. Is it possible to get a notification for rename? I see that RENAME is available via the event API, is it preferable to use the event API? I saw another stackoverflow question asking about webhook vs event (Box webhooks deprecated in favor of long polling?) and the answer said webhooks are still valid, but didn't really comment on webhook vs event.
I'd prefer webhooks since they are a close fit to how I get changes for Dropbox accounts but it appears from the docs that event has more information/options. Also, it seems it's possible to miss a Box webhook notification which could create an inconsistent state between Box the model in my application.
Which to choose?
Many thanks!
I don't believe it's possible to get a WebHook notification when an item is renamed.
The choice between WebHooks and events really depends on what you're building. WebHooks are generally easier to use, but the events stream can give you more power. In your case, you'll probably need to use events so you can be notified of a renames.
It's also worth noting that if your application really depends on staying in sync with the state of Box, you're better off using the events stream. It lets you specify a last known position in the stream so that you can catch up on any missed events if your application goes offline.
In my application hitting service call on every page navigation and showing MessageDialog to user.
My problem was when I hitting service call (await) on page navigation "Page1" to "Page2" whereas service call taking certain time to complete meantime user taps back to "Page1"
In that case user seeing "Page1" and await service call completed on "Page2" and showing that service response message in "Page1".
How can I avoid MessageDialog suppose user navigates back from that page.
First of all, you should avoid using MessageDialogs for this sort of information. You should think about using a ProgressBar or ring to indicate that your app is performing a task in the background (calling your service). This way, your users won't be interrupted in their interactions with the app, yet still be aware that something is going on in the background.
If you are using an MVVM pattern, your ViewModel or Model classes should be doing the heavy lifting of talking to the service. If your app absolutely must show MessageDialogs, I'd recommend creating an event in your back-end classes that will cause the UI to show the MessageDialogs on completion of the call. That way you can subscribe to those events when you load the page, and unsubscribe from them when you navigate away. In this way you can avoid messages appearing from Page2 when you are on Page1 of your app.
I'm building some very basic analytics for in-house WinJS apps. Take this to mean that a 3rd-party analytics solution would both overkill and/or unworkable and/or against the 3rd-party providers terms of use as they generally disallow capturing personally identifiable information about the user, and in this case that is a business requirement.
The thing I'm trying to do is determine how much time is spent in multiple apps, and in areas within certain areas of the app. For this I obviously need to know when they enter and leave.
All the documentation I've found says to use the WinJS.Application.oncheckpoint event or the Windows.UI.WebUI.WebUIApplication.onsuspending event, which really seem to be two access points into the same basic concept. The problem is this doesn't accurately reflect when the user leaves the app! Suspend seems to happen only after the user has switched to another app, plus about 10 seconds ...... if the system feels like it.
If the user simply hits the Windows key to go out to the Start Screen and just sits there, the app continues to run indefinitely (calls to setInterval are able to affect state) even though the app cannot be seen!
I understand this is a bit of an edge case, but is there any more reliable way to tell when the user can't see the app, for lack of a better definition?
Notes:
I did look at the Cordova 2.7 code for Windows 8 and they are using the checkpoint event to drive the Cordova pause event.
App Visibility section on Application lifecycle seem to address this. This means registering for `msvisibilitychange' event, to know when user moved away and moved back to your app.
default.js:
document.addEventListener('msvisibilitychange', function ()
{
console.log('visibility changed');
console.log(document.visibilityState); // 'hidden' or 'visible'
});
In addition, suspending, resuming and activated events also needs to be handled.
default.js:
Windows.UI.WebUI.WebUIApplication.onsuspending = function ()
{
console.log('suspending');
}
Windows.UI.WebUI.WebUIApplication.onresuming= function ()
{
console.log('resuming');
}
Needless to say, that nuance of ordering, and/or event being absent cases needs to be handled. For example - if the user moves away and comes back quickly, visibilitychange event will be received. whereas if user does not come back suspending event may come after some time. if the app is not terminated, it may be followed by resuming event. otherwise, activated event.
regards spending time on specific pages, page ready and unload method should work. unload() will not get called if the app is suspended or terminated.
https://developer.mozilla.org/en-US/docs/Web/Reference/Events/visibilitychange
Use the visibility change event to recognize when the user can no longer see the app.
I have an html form which includes a textarea box and a submit button that calls the API (say the Google Translate API, or Twitter API).
Now I wish to get rid of the submit button and automatically call the API once the user has entered input.
I also wish to have a limited number of API calls: ideally just one API call once the user has finished typing in that textarea.
What would be your recommendation on:
the language to use (javascript, php, other)?
the process: what triggers the API call?
Any pointer would be appreciated.
Edit -> About the "finished typing" part: I will never know if the user has finished typing. The only thing I might know is that there is no typing since x seconds. It would be great if I can detect inactivity since 1 or 2 seconds and trigger the API call. Is that possible and how?
PoltoS has given you information about keyUp and setTimeout. Also you can handle onBlur() event. Form is submitted using submit() method of the form. See examples here. BTW you will probably find the sample for all parts of your question there.
You can bind keydown/keyup events of your field to some function that runs setTimeout (with 5 seconds delay) after clearing old one. Once the function mentioned in setTimeout is called - the user has not typed for 5 seconds - execute your API call.
Better would be to show a countdown timer on the right to let user understand that something would happen in 5 or 10 seconds.
And of course it should be done using JavaScript - no additional request to server needed