Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
AngularJS has a $timeout service which acts as a convenience wrapper around setTimeout.
Why is there no equivalent for setInterval?
Since $timeout is calls scope.apply after each call it can get expensive. However creating a simple interval you can decide what watches and apply calls are needed to keep it clean.
For example, if you interval was running once every minute to check if the user's values had changed and optionally saving it if the values had been changed since the last check. Depending on how you write the code, you may never need to update the web page, so your interval can get by without triggering an update.
That doesn't answer the question directly of why $interval isn't provided by default, but I suspect it is because since it is simple to create your own with you specific requirements, it is better to leave it open for you to enhance, instead of providing a default implementation that is too complex, or too inflexible.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 months ago.
Improve this question
When making API calls in React, should they all be asynchronous?
Is this a one-size-fits-all answer, or is this scenario-based? If so, what are some good examples of where to use async calls, and where not to use them?
The only way to perform sync API calls is by using XMLHttpRequest in a very particular fashion which was deprecated a long time ago.
More modern APIs like fetch do not support sync requests even as 1st April joke.
So, yes, it's a very good idea to keep your API requests async, always.
Sync requests are problematic, make your app perform really bad & are just conceptually silly.
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
I'm making a react app using Apollo client for GraphQL queries, where I want to update upvotes state, so that upvoting doesn't take time for users. If I don't, I have to wait for the mutation to return data, which takes 1 second. Is there any way to fix this?
I think optimisticResponse is your solution. (as #xadm pointed out)
https://www.apollographql.com/docs/react/performance/optimistic-ui/
If you already have implemented the update function in your mutation (which is normally used to update your query, otherwise you should), it will be called twice, once instantly with your optimisticResponse, and once again with the server response.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I have found some components that are not updated with the last React version, however, those components work. But I was wondering if those components are not updated would be the best option or a good practice to try to implement the libraries in React without the npm packages?
Thanks.
I'm my experience, it'll depend upon the product you're working on. IE. you're working in a UI that is not likely changing and once it's done, it'll remain the same for some time (rare case), and it's not too complex. I'd go for the component even if it's not that updated.
If the benefits from constructing the component yourself (long term maintainability, extensibility, etc.) are important to your project and it won't take that much time, maybe it'll be the best option.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Let's say I have a page with two buttons and a content control. I also have a View-Model defined for this page. When I press each button a specific view-model is bound to a content control, so buttons are used to switch between views. The problem is, when view is switched some data needs to be downloaded (doesn't matter from where, it could be a database) via a view-model - and I don't really have an idea where to put code responsible for that (i.e., code that starts downloading data). Is constructor a good place for it?
Usually the ViewModels have a specific method (mostly called Init), that performs data initialization. Constructor should not be used for these purposes, because it should just construct the object, nothing else. Moreover - you will probably want to perform data loading asynchronously, so constructor is again not very well suited for this.
The Init method should be called just when the navigation is performed, so you can pass your navigation parameters to it.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Where is it better
in bootstrap.php or app_controller.php
it's needed for geolocation.
In 1.x use
RequestHandlerComponent::getClientIP()
it already covers all problems you might be facing
and yes, "at the point in time at which at which you need it"
For 2.x it's best to use
$this->request->getClientIp()
from inside the controller as documented on http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html#requesthandlercomponent
It really depends on what you are using the IP for. If you need it in all parts of your code, then the app_controller is the place to put it. If you only need it for log in for example, then put it in the users_controller.
That being said, it may be better to write a session variable and then it is available wherever you need it without the code overhead.
echo $_SERVER['REMOTE_ADDR'];
or
$remIP = $_SERVER['REMOTE_ADDR'];
at the point in time at which at which you need it. That way you can be sure it's current, although I'm not sure if it could get stale. It's there in the server all of the time, so there's no concept of when to assign it - just get it when you need it.