Giter VIP home page Giter VIP logo

Comments (16)

jhiemer avatar jhiemer commented on May 18, 2024

Hi,
I am searching for exact the same thing namely $state.reload(), which would be really helpful, when I have an overview with entities, and one entity is delete. Then it should reload the current view.

from ui-router.

ksperling avatar ksperling commented on May 18, 2024

The controller already gets re-created when parameters change.

However the behaviour is somewhat different from $route in that

  • only search parameters that are listed in the URL pattern are treated as parameters for the state (e.g. '/a/{id}?from&to' would treat 'id', 'from', and 'to' as state parameters)
  • search parameters that are listed are treated the same as path parameters as far as reloading is concerned. I.e. reloadOnSearch=false is not supported at this time.

from ui-router.

ksperling avatar ksperling commented on May 18, 2024

@sqs in the line you're referring to, 'locals' will only be the same object if the state AND parameter values for the state are the same. In all other cases the view (and controller) will be reloaded.

from ui-router.

sqs avatar sqs commented on May 18, 2024

Got it. I'll try to come up with a jsfiddle or test case that reproduces what I was seeing.

from ui-router.

lmessinger avatar lmessinger commented on May 18, 2024

Just found this... I actually need the opposite: reloadOnSearch = false. this is because I need to change stuff inside the view directive and the controller when only the parameters change - but I need to keep them as before. Wondered what is the reason that its not supported? wouldnt you feel that it is wasting speed and memory?

would you recommend that we add it locally for us (for example, by

  var keep, state, locals = root.locals, toLocals = [];
  for (keep = 0, state = toPath[keep];
       state && state === fromPath[keep] && (!reloadOnSearch || equalForKeys(toParams, fromParams, state.ownParams));
       keep++, state = toPath[keep]) {
    locals = toLocals[keep] = state.locals;
  }

)

and let me join the others: GREAT PROJECT!

EDIT: i've tried that, works so far in the sense that it does not cause reload. However, best if we could add a $watch on $stateParams service to get the changes. any hints would be appreciated..
EDIT 2: preventing the reload prevents it from being entered into the history, so back button does not work for those parameter changes that didnt make it into a reload

from ui-router.

ksperling avatar ksperling commented on May 18, 2024

@lmessinger what exactly are you trying to gain by not reloading the controller? Is there actually information held by the controller that you need to keep, or is it meant to be some sort of optimization?

The reason to create the controller from scratch is so that it can (either itself or via the 'resolve' property of the state or view) load data based on the current parameters. It sounds to me like managing all that by hand via watches is rather complicated and error prone. Compared to actually loading some data remotely, surely the overhead of re-creating a controller is tiny, and any caching would be much better done via a service.

$state also currently makes no arbitrary distinction between path and search parameters, so 'reloadOnSearch=false' would have to be something like 'reloadOnParameterChange=false'.

from ui-router.

lmessinger avatar lmessinger commented on May 18, 2024

Thanks @ksperling for both a great module and your answer. first about the
use case - I'm developing a search panel, represented as a state and
panel, and taking its data from the state parameters. the user types in the
input box the search text and that is directly examined by the search panel
and make new calls to the server

Except from performance, which might be an issue on weaker devices, the
other reason that I have is entry and exit animation.

in my system, every directive has an entry and exit animation. the plan is
to use onEntry/onExit for that. if the view directive is re-created on each
parameter change, I wouldnt be able to use these but would have to find a
different method (probably still need to do some change to ui-router
original code)

so far i've implemented the patch I've discussed above. but that does not
allow me to use stateParams at all in my controller - cannot put a
watch/observe on it. wondered if there's a way to do it...

thanks again
Lior
On Tue, Mar 19, 2013 at 9:07 PM, Karsten Sperling
[email protected]:

@lmessinger https://github.com/lmessinger what exactly are you trying
to gain by not reloading the controller? Is there actually information held
by the controller that you need to keep, or is it meant to be some sort of
optimization?

The reason to create the controller from scratch is so that it can (either
itself or via the 'resolve' property of the state or view) load data based
on the current parameters. It sounds to me like managing all that by hand
via watches is rather complicated and error prone. Compared to actually
loading some data remotely, surely the overhead of re-creating a controller
is tiny, and any caching would be much better done via a service.

$state also currently makes no arbitrary distinction between path and
search parameters, so 'reloadOnSearch=false' would have to be something
like 'reloadOnParameterChange=false'.


Reply to this email directly or view it on GitHubhttps://github.com//issues/46#issuecomment-15153374
.

Lior Messinger
1-646-3730044
www.Lgorithms.com

from ui-router.

ksperling avatar ksperling commented on May 18, 2024

@lmessinger Hmmm. We're going to have animation support via ngAnimate (#22).

If I remember correctly, reloadOnSearch=false in $routeProvider causes the entire route change to be omitted, i.e. no $routeChangeStart / $routeChangeSuccess event etc. So if we were to follow the same logic, we would just update $stateParams, but not fire any onEnter/onExit or resolve new locals or anything. It seems like this could cause all sorts of odd effects though, for example in the current code any onExit callback that gets $stateParams injected would see the parameters that were valid when the state was first entered, and any subsequent changes would be invisible -- however this could be fixed.

On the whole I'm not really convinced of the need for reload=false yet, especially for performance reasons: If performance is really an issue, we should do some profiling and see how we can make things faster without making people essentially do their own state management for parameters.

As far as your watch goes, try watching $state.params; $stateParams always retains the same object identify (it can't change to a different object because its managed by $injector), only its contents change. $state.params is actually a new object when the state or any parameters change.

from ui-router.

lmessinger avatar lmessinger commented on May 18, 2024

Thanks @ksperling . Not sure if ngAnimate (looks very cool!) will solve it since if, upon parameters change, the view directive (and all of its child directives) will be re-created, i suspect they will be re-animated. and we dont want that if we plan to keep the view.

Thanks for the watch advice

from ui-router.

jssebastian avatar jssebastian commented on May 18, 2024

On the whole I'm not really convinced of the need for reload=false yet, especially for performance reasons: If performance is really an issue, we should do some profiling and see how we can make things faster without making people essentially do their own state management for parameters.

@ksperling: I don't think it is about performance, but more about ui flicker. In my experience with angular so far so long as there are no AJAX queries (which we can cache) the page displays fairly fast, but there are a lot of things that flicker.

e.g., ui-bootstrap's collapse/accordion does a little bounce, the new angular animations do their thing, my d3.js-based graphs take a moment to render, ng-show/ng-hide/ui-if sometimes starts in the wrong state and quickly flickers to the right one, etc.

This is not so bad on page load (in some cases it is even done on purpose, such as animations). But if it happens when a user is navigating within a page I think it is really bad.

An example: a table view with a next page button that updates the anchor part of the url to reflect which page is being shown (like gmail does). But every time you click next, the whole page flickers away and then appears again (including ui components independent of the current table page). Furthermore, the user loses the scrolling position and finds himself back at the top of the page.

from ui-router.

ksperling avatar ksperling commented on May 18, 2024

@jssebastian any idea what's causing this flicker? One thing that I've found quite odd is that e.g. ng-view adds the 'raw' template to the visible DOM before running the compile/link on it. In theory the compile and link should finish before the JS code finishes (i.e. before the browser starts rendering), but maybe this is not always true?

from ui-router.

jssebastian avatar jssebastian commented on May 18, 2024

@ksperling: from some more testing, things are not as bad as I assumed. Basically there seems to only be flicker if some state variable in my scope is briefly in the wrong state, which typically happens while I am loading asynchronously, so caching or keeping some state in a service should be able to fix most of these issues. If I find anything specific that I cannot fix on my side I will report it.

However, my d3.js-based graphs do take a moment to re-render, and losing scrolling position remains a problem.

from ui-router.

ksperling avatar ksperling commented on May 18, 2024

@jssebastian scroll position is something we have to look at... clearly the $anchorScroll approach with it's default scroll-to-top behaviour isn't appropriate for ui-router anymore, see #110

from ui-router.

brennancheung avatar brennancheung commented on May 18, 2024

So I don't know if there is a better way to do this but I had a similar problem. I had one view with a list of entities, and another that allows me to add entities. When I add the entity and submit it, the list was not being updated. I eventually found that I can use $rootScope.$broadcast('entitiesChanged') and then in the other controller I can do $scope.$on('entitiesChanged', function...). When I receive the entitiesChanged event I fetch the list from the RESTful endpoint again.

from ui-router.

ksperling avatar ksperling commented on May 18, 2024

@brennancheung events seem like a good way of doing this sort of thing. If your sending from controller that's in a child scope of the one interested in the event you should also be able to use $scope.emit(), which should be more efficient in this case as the event would only traverse upwards, not to all other branches of the scope tree.

from ui-router.

nateabele avatar nateabele commented on May 18, 2024

Moving the discussion to #125, since the complex parameter implementation will allow this.

from ui-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.