My program fills an array with data from a facebook page feed but every time i go from one tab to another it wants to reload this data, is there any way i can cache this array so that it will not reload the information unless its changed?
This is exactly why your Views should not contain Service logic. Instead, your View should dispatch an event asking for the service call and your Controller (you do have one, right?) should catch that event and decide whether to act on it or not.
How do you know the data hasn't changed without reloading it?
Maybe what you need is to store the timestamp of the last service call, than measure the amount of time before executing the service call again.
Perhaps with a 5-minute timeout, if the user continuously changes tabs within 5-minutes from the last service call, the array persists previously loaded data.
After 5-minutes, if the user changes back to that tab the service call can fire, load data, than update the timestamp to prevent loading.
Related
I have a react-redux application which:
Loads N records from the database depending on a "limit" query parameter (by default 20 records) on first application load (initialization)
Every 10 seconds app requests same (or newer) records from the database to update data in real time
If a user changes filters - app requests new records from the database according to the filter and re-renders app (+ changes interval to load data according to the filters)
If users scrolls down, the app automatically loads more records.
The problem is that if a user for and instance tries to filter something out and at this same time interval is loading more data, 2 requests can clash and overwrite each other. How in react-redux app I can be sure in a request sequence. Maybe there is a common approach on how to properly queue requests?
Thanks in advance!
I am not sure what you mean by 'clash'. My understanding is that the following will happen:
Assuming that both requests are successful, then data is retrieved for each of them, the redux state will be updated twice, and the component which renders the updated state will render twice (and the time passed between the two renders might be very short, which might not be very pleasant to the user)
If you want only one of these two requests to refresh the component, then a possible solution may be the following:
Each request starts, before retrieval of data from the database, by creating a 'RETRIEVAL_START' action. 'RETRIEVAL_START' will set a redux state variable 'retrievalInProgress'
If you want, in such a case, to get results only from the 1st of the two requests, you can check, before calling the action creator from the component, if 'retrievalInProgress' is on. If it is, don't call the action creator (in other words, do not request data when a request is in progress). 'retrievalInProgress' will be cleared upon successful or failed retrieval of data.
If you want to get results only from the 2nd of the two requests, then make 'retrievalInProgress' a counter, instead of a boolean. In the 'retrievalSuccess' action of the reducer, if this counter is higher than 1, it means that a new request already started. In this case, do not update the state, but decrement the counter.
I hope that this makes sense. I cannot be 100% sure that this works before I test it, which I am not going to do :), but this is the approach I would take.
I have a $http.put function that updates my database, this happens on a button click. After I update the database once, and stay on the page, with no interaction at all the update function gets called and will update the database with the last information that was inputted.
I've triple checked my code, there is only one occurrence of my update function being called. And the $http.put is inside $scope.update that is an anonymous function that calls the $http.put.
If I update information and then leave the page, and then come back the function does not fire on it's own.
Here is my Github for the project. I will pull out any specific code that you want to see, but I'm not sure what to show because there are 4 files involved. Those files are
(client/scripts/app.js)
(routes/products.js)
(public/views/routes/adminIndex.html)
(public/views/routes/modProduct.html)
Code is Here
Add a console.trace() just before the $http call to see what is calling it.
You can also use the developper console of your browser and add a breakpoint that will stop the code execution and let you inspect everything (stack trace, current context, etc). Chrome is particularly good at that.
I'm trying to figure out a user friendly way to pass messages to users from my Apex code. I have a trigger which fires after insert/update of a lead, which then filters the list of updates and triggers a #future method which pushes the lead data out to an external web service and updates the converted account with some of the returned values.
I'd like to do the following (where X, Y and Z are any number of leads from 1 to 50)
notify the user converting the leads that leads X, Y and Z will be exported (I'll know this during the trigger execution).
notify the user whether the export succeeded or failed (which will be known for each of X, Y and Z when the #future method runs).
What is the recommended way to pass this information back to the user? I'd prefer not to use email (as this would trigger one email per record, which is pretty spammy and unpleasant). Is there another way to inject notification messages into a page? I've tried ApexPages.addMessage() but it doesn't seem to do anything for me (no error, but no notice either).
addMessage() works with both Visualforce pages and standard pages when there's a current page active, so using this in the trigger should work fine if the user is firing the action from a button / VF page. Using this won't work from your #future method however because it runs asynchronously in the background.
Maybe the best solution would be to use a custom message object, which has a list of fields modified, when, and has a lookup to the appropriate user (or uses them as the owner). You could then create a simple VF page and controller which when viewed queries for records in that object related to the current user and provides an option to delete them (you could automatically delete them after pulling them from the DB but you run the risk of the user not actually noticing a message). You can then take this page and use it as part of a dashboard component, so anytime the user is viewing their Home page they could see a list of notifications.
Finally another option might be making use of Chatter, pumping the messages to the user via that which will then also show up in digest emails etc..
I am planning to have a (Telerik MVC) grid in which each row has a button. On click, a boolean will be updated in the DB via ajax and the callback function will set a "checkmark" image in one of the row's cells. The user should be able to click on multiple rows in rapid-fire fashion, and I'm trying to anticipate any problems if he does so. Is there a possibility of contention either in the DOM or in the database server?
To make sure that user experience does not suffer, here's what I'd do:
Create an array of objects to be update
Every time an checkbox is clicked, add/update it to/in the array with the value - this will make sure that multiple clicks to the same checkbox will result in only one AJAX call
After adding a check box to array, start the AJAX update process
On AJAX response, check if there are any items in the array to be processed and repeat
The biggest factor will probably be how quickly your server handles the Ajax request. If it takes a while, then the user experience will suck.
You could possibly make this better by adding the keys to a variable, and just sending to the server periodically, eg:
User clicks an item
Add key to array
Use window.setTimeout() to kick off the send function in x milliseconds
User clicks another item
Add key to array
Timeout already set, so doesn't do anything more
Timeout expires, code runs, sends both keys to server in one request
User clicks an item
Add key to array
Use window.setTimeout() to kick off the send function in x milliseconds
etc.
I have a form where the user can remove notes from an order. I do not want the notes store to call the destroy url with the deleted notes unless the user clicks the save button. Should I be able to call suspendEvents(true) on the store and then call resumeEvents later, when the user clicks save, and have it post to the destroy url for all of the deleted notes? Is there a better way to do this?
The best way to handle this would be to privately maintain a collection of data containing the necessary info for the notes you want to destroy. You can hook the 'afteredit' event to append to this collection for later destroying.
After that, all you'd need to do is add a toolbar button to the grid that has a handler attached to actually pass the collection data to your server and clear out your collection of notes to destroy.
Hope this helps, although I might be misunderstanding what you are attempting to accomplish as your description is a little tough to fully wrap my head around.
Set the autoSave:false config option on the store, then every time a user removes a note from the order, just call store.remove(noteRecord) -- when the user clicks the save button, call store.save() and all modified records will be sent to the server (assuming you have a writer configured for the store)