Is there a way in the base puppet to tell you that the performance has already been shown in the region?

Given something like this:

View = Backbone.Marionette.ItemView.extend({ }); myView = new View(); //region already exists myLayout.region.show(myView) //some time later this gets called again: myLayout.region.show(myView) 

I can see currentView in the docs, but this seems to apply during initialization. As soon as the view appears, can I request a region to see the view? Perhaps an instance or view type would be useful. Looking at the Chrome debugger, I don't see any properties / methods in the region that could help.

The motive for this is that I again do not show the static element in the area if it is already displayed, since this can (especially if the images are involved) cause a slight flickering effect on the screen.

thanks

- Justin Willie

+6
source share
3 answers

you can add a condition before calling the show method:

 if (myLayout.region.currentView != myView) myLayout.region.show(myView) 

therefore, if you try to call show with the same View , it will not be displayed.

if you want to call region.show(myView) after you can check this way:

 if (_.isUndefined(myLayout.region.currentView)) myLayout.region.show(myView) 
+11
source

You can check the isClosed and $el attributes of the view. Sort of

 if (myView.isClosed || _.isUndefined(myView.$el)) { myLayout.region.show(myView); } 

Similarly, a region checks whether a view is closed or not:

 show: function(view) { this.ensureEl(); var isViewClosed = view.isClosed || _.isUndefined(view.$el); ... 
+7
source

I go out on a limb and assume that the OP question is based on the behavior of the application when navigating various parts of the application through an anchor mark in navigation or something similar.

This is how I found this question, and I briefly thought that the answers would save my day. Although both answers are still correct, they do not completely solve the problem I am facing. I wanted to show a constant navigation bar. However, I did not want it to appear on the login page. I was hoping that by discovering that the region was already shown or not, I could correctly let the display logic take care of this.

As it turned out, we were on the right track for the implementation of the regions, since it provides granular control, but even after implementing the above, I found that my navigation bar is still โ€œflickeringโ€ and essentially completely reboots.

The answer is actually a bit ridiculous. Somehow in all the Backbone tutorials and studies that I have been doing the last two weeks, I have not had to deal with the need to implement a javascript interface to interrupt the behavior of a regular link. Whenever a navigation item was clicked, the entire application rebooted. Routing functioned, so the contents were correct, but the flicker was crazy.

I added the following to the app.js file right after Backbone.history.start ({pushState: true}); code:

 // Holy crap this is SOOO important! $(document).on("click", "a[href^='/']", function(event) { if (!event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) { event.preventDefault(); var url = $(event.currentTarget).attr("href").replace(/^\//, ""); Backbone.history.navigate(url, { trigger: true }); } }); 

Check out this article for some explanation of keyPress stuff. http://dev.tenfarms.com/posts/proper-link-handling

Boom! After adding this material to my application, it no longer completely reboots!

Disclaimer: I am very new to Backbone, and the fact that the above was such a revelation to me makes me think that I can do something wrong elsewhere, and this behavior should already exist in Backbone. If I made a giant mistake here, please comment and help me fix it.

0
source

Source: https://habr.com/ru/post/951627/


All Articles