-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refetch resolves without reloading the state #3399
Comments
+1 |
did you manage to achieve it somehow? |
@mkoczorowski no, I haven't. I don't think there's any workaround for it but it's a very common use case and I hope that @christopherthielen will consider implementing it. |
I've encountered this problem so many times. Most often when:
I've "solved" this with However, I think that ui-router can solve the re-
|
Alternatively, please pilfer my angular.module('test').service('$againable', function ($q) {
return function $againable(future) {
return (function $again() {
var deferred = $q.defer();
$q.when(future(), function (result) {
deferred.resolve(angular.merge(result, { $again: $again }));
}, function (result) {
deferred.reject(angular.merge(result, { $again: $again }));
});
return deferred.promise;
})();
};
}); And then: resolve: {
dataSet: function ($againable, $http) {
return $againable(function () {
return $http.get('/some/data/set').then(function (response) {
return response.data;
});
});
}
} Such that the resolved values have the controller: function ($scope, dataSet) {
$scope.dataSet = dataSet;
$scope.refresh = function () {
$scope.dataSet.$again().then(function (dataSet) {
$scope.dataSet = dataSet;
});
};
} |
Thing 1I agree with the intention behind this feature request. I'm am being very careful about feature requests like this because it fundamentally alters one of the core concepts in ui-router. I'm not opposed to enabling a feature like this, but I want to think through the ramifications. I'm also afraid of adding additional mental models, to avoid "fragmentation" of the userbase. Thing 2I think that Observables + dynamic parameters can be used (today) to achieve the desired result. Thing 3There is a low level (internal) resolve API that could be used to re-resolve individual resolvables. Resolves are stored on an array of The You could use this internal API in a component as follows:
Of course, these steps should be abstracted into a helper of some sort. |
related feature request: #2888 (comment) |
@christopherthielen thanks for your response and I understand your concerns about adding "additional mental models" but I think that backwards compatibility shouldn't be an issue and users who never needed this feature should not notice any difference as it would be just one of the optional flags. As for using internal resolve API, I don't think it's a solution in my case because the way you proposed it, I would have to inject I haven't used observables in UI-Router's context so would appreciate if you could share an example of Observables + dynamic parameters to achieve the desired result. |
Hi @christopherthielen , |
@dARKaRK If you look at the blame view for This is a pretty good example of why production code shouldn't rely on internal APIs unless absolutely necessary - @christopherthielen's suggested workaround for re-resolving was broken by this change only a few months after he posted it. |
This issue has been automatically marked as stale because it has not had This does not mean that the issue is invalid. Valid issues Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had This does not mean that the issue is invalid. Valid issues Thank you for your contributions. |
This is a:
My version of UI-Router is: v1.0.0-rc.1
Feature Request
Currently the only way to re-resolve data in previously active states is by specifying
{reload: true}
inui-sref-opts
directive or$state.go()
calls. This is a huge limitation where progressive rendering is required and complete state reload is not desirable.A simplified use case:
Let's say we have 2 states, a parent
cards
state representing a list of cards which has a couple of resolves and a childcards.card
state for editing individual card. Upon card update to the server we return to the list of cards but the change is not reflected becausecards
state has not been reloaded and fresh list of cards has not been fetched from the server.Reloading entire state using
{reload: true}
is undesirable because it re-resolves all dependencies even if some of them don't change at all.Proposal:
Implement
{reFetch: true}
which would be similar to{reload: true}
to only re-resolve dependencies that are subject to change without reloading the state. I think a good place for this would beresolvePolicy
to declare all resolves that should be re-fetched if{reFetch: true}
was set viaui-sref-opts
directive or$state.go()
.For instance:
Then on transition start we could check if
reFetch
is true and only re-resolve those resolves that hadrefetch: true
declared inresolvePolicy
.I have created a plunker to illustrate the desired behaviour http://plnkr.co/edit/5CciECkWZiFv9lcBmGZT?p=preview
The text was updated successfully, but these errors were encountered: