Giter VIP home page Giter VIP logo

Comments (8)

dsawardekar avatar dsawardekar commented on July 29, 2024

@heartsentwined How about using session.destroy() then recreating it on the container.

session.destroy();
container.unregister('session:main');
container.register('session:main', App.DefaultSession || Ep.Session);

I'm still figuring out Epf, not sure this is the right way.

from epf.

heartsentwined avatar heartsentwined commented on July 29, 2024

Folks over at ember-data recommended a similar solution too, but got rejected by the devs on grounds that

we actually pass the store reference around and those references would not be updated. We probably should have a method to do this.

Would love to hear from @ghempton on this suggestion.

from epf.

ghempton avatar ghempton commented on July 29, 2024

This is a good question. Creating a new top-level session (e.g. adapter.newSession()) is the answer I want to give, but alas the ember-data folks are correct that the injected references will not be updated.

If we want the references to be updated, a higher level approach needs to be taken and all the controllers and routes need to be re-created. Perhaps the entire application could be reset using Application.reset()?

Alternatively, it would be fairly straightforward to create an api such as session.unload(), but that seems kind of fragile for this use case. Thoughts?

from epf.

heartsentwined avatar heartsentwined commented on July 29, 2024

I haven't dug deep yet, but from the observed behavior it seems that load(), find(), and friends (if any) does this:

  1. if the passed tuple of ModelClass + id is present in cache, return it immediately
  2. otherwise query the server for it

So I think that the unload() api can simply clear the cache, and mark all tuples as unseen. This will allow you to maintain the same reference to the session. However, I am not sure if there are other traces unique to the current session that ought to be cleared.

An Application.reset() is as unattractive as the forced-refresh workaround. Say Alice is looking at a dress, and urges her friend Cindy to buy it. Alas, Alice needs to log out so that Cindy can log into her account. The refresh / app-reset approach will clear everything, then try to reload it from the URL (and maybe cookies) alone. Granted, a well-designed app should be able to do that, although it will quickly get tedious to keep track of, say, the "yellow" color checkbox right next to the dress. Not to mention that the page goes "unresponsive" for a while (waiting for server to confirm log out success), then goes "blank" (refresh), and yet more wait time for the app-reload. If possible I would prefer to keep the ember app in place, and just let the little sign in/out box at the corner does its magic without interrupting Cindy's gaze at the beautiful dress. A customer!

from epf.

heartsentwined avatar heartsentwined commented on July 29, 2024

As discyssion over at the ember-data thread has mentioned, Application.reset() is good for unit-testing though. However, it's even better to destroy() everything - so that already takes care of this use case IMO.

from epf.

ghempton avatar ghempton commented on July 29, 2024

I'm for adding an unload method. It shouldn't be too hard, short of a few edge cases. Will mark this issue as a feature request for it. This will also suffer from dangling references to unloaded models, however.

I can't help but wish it were easier to swap out session instances as this use case seems perfect for it. I wonder if there are some optimizations that can be done around App.reset (e.g. keeping the models around and manually adding to the session).

from epf.

heartsentwined avatar heartsentwined commented on July 29, 2024

👍

from epf.

mantenie avatar mantenie commented on July 29, 2024

👍

from epf.

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.