Skip to content
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

Use of ViewModels in session is not transparent #682

Open
selo-ecube opened this issue Oct 19, 2017 · 3 comments
Open

Use of ViewModels in session is not transparent #682

selo-ecube opened this issue Oct 19, 2017 · 3 comments
Labels
Milestone

Comments

@selo-ecube
Copy link

selo-ecube commented Oct 19, 2017

  • When ViewModels are serialized to the session and then deserialized, the data from ViewModel.extendedViewModel is lost.
  • Since ViewModel.extendedViewModel works fine in Handlebars, losing this information during session handling was unexpected to me.
  • We stumbled upon this problem when we wanted to add a boolean field to MiniCartBean. Not using the extended view model but introducing a subclass of MiniCartBean is undoable because
    • Inconsistent use of (Truncated)MiniCartBeanFactory #681
    • CartInSession having all private fields so a lot of information needs to be duplicated in the subclass
    • MiniCartBeanFactory.create(Cart) not delegating to a separately overridable method that creates a Bean instance and at the same time being invoked via super.create(...) from TruncatedMiniCartBeanFactory so our subclass of TruncatedMiniCartBeanFactory cannot override MiniCartBeanFactory.create(Cart) in an effective way. Of course we could start copying more of TruncatedMiniCartBeanFactory but code copying has limits, right?
  • We would like to show a message in the minicart explicating that it has been truncated. We're not able to do that right now due to above limitations.
@lauraluiz lauraluiz added this to the v1.0.0-RC1 milestone Dec 28, 2017
@lauraluiz
Copy link
Contributor

@selo-ecube I just re-read the last line and realized that you may have needed some action to fix this for your project. Sorry! I understood the issues as just feedback to fix in next releases (which we are working on at the moment). Do you still need help with that?
Regarding the topic itself, we are getting rid of ViewModels, specially in Session, so we are working in the right direction.

@selo-ecube
Copy link
Author

Sorry for the late reply. Yes, we need help with that, but it's ok to wait until you fixed it. Thanks for getting back!

@lauraluiz
Copy link
Contributor

Unfortunately we are working on that in the 1.0.0-RC1 version which is completely different from the v0.x.x, so I don't think we could painlessly provide a fix for the latter version. But these are the key changes involved:

  • We don't use ViewModels, we use the JVM SDK models directly in the templates (except for very few exceptions).
  • We only keep in cache JVM SDK models such as cart and customer. In Session we keep ID and version of those models, and any other quick and non-sensible data that we may often need.
  • Then we just request the cached cart and put it in the page data to the template. The template takes care of extracting all info for the mini cart.

In your case you told me in another issue that you didn't want to go the cache solution, but it's the only solution that will solve this I'm afraid. So for your version I can either point you to the v1.0.0-RC1 development branch files so that you can copy them to your project and drop the Session classes from v0.x.x, or we can discuss which would be the best way for me to integrate them in v0.x.x so that it can help your case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants