framework7 icon indicating copy to clipboard operation
framework7 copied to clipboard

[v3] stackPages needs a maximum

Open emilycestmoi opened this issue 8 years ago • 8 comments

This is a (multiple allowed):

  • [ ] bug
  • [x] enhancement
  • [ ] feature-discussion (RFC)
  • Framework7 Version: 1.4.2
  • Platform and Target: Cordova iOS

When enabling domCache: true, it would be nice to have a way to limit the number of pages that get cached. Something like domCacheMax: 5 to limit the max cached pages to 5. I like using domCache because it preserves the exact page state when a user hits back, but there needs to be a way to limit this so it does not get out of hand.

I added a hack in a plugin that does this for myself (I'm using jquery).

if (view.params.domCache && view.params.domCacheMax && view.history.length > view.params.domCacheMax) {
                    var removed = view.history.splice(1, 1);
                    var $page = $(view.pagesContainer).children('.page[data-page="' + removed[0] + '"]:first');

                    if (view.initialPages.indexOf($page[0]) == -1) {
                         app.pageRemoveCallback(view, $page[0], 'left');
                         $page.remove();
                     }
}

emilycestmoi avatar Jun 15 '16 20:06 emilycestmoi

@nolimits4web what do you think?

ZanderBrown avatar Mar 12 '17 23:03 ZanderBrown

@ZanderBrown I think it can be useful, will add it to roadmap

nolimits4web avatar Mar 13 '17 21:03 nolimits4web

@nolimits4web did this make it to V2?

ZanderBrown avatar Jan 13 '18 10:01 ZanderBrown

@ZanderBrown no, let me mark it as v2 feature request

nolimits4web avatar Jan 13 '18 13:01 nolimits4web

@emilynewsom, where did you put this hack of yours? what specific file

pluckannfeel avatar Nov 15 '18 03:11 pluckannfeel

@nolimits4web is this applied in v3 already?

pluckannfeel avatar Nov 16 '18 02:11 pluckannfeel

@pluckannfeel I created a framework7 plugin that does a lot of hacking but i've stripped out the other stuff. Something like below. This is from 1.4.x unfortunately, I haven't done much work with f7 lately:

(function(root) {
    Framework7.prototype.plugins.pages = function(app, params) {
        return {
            hooks: {
                appInit: function() {
                    var originalLoad = app.router.load;

                    app.router.load = function(view, options) {
                        var url = options.url;

                        if (!url || view.url === url) {
                            return originalLoad(view, options);
                        }

                        if (view.params.domCache && view.params.domCacheMax && view.history.length > view.params.domCacheMax) {
                            // skip home
                            var index = 1;
                            
                            view.history.splice(index, 1);
                            var $existing = $(view.pagesContainer).children('.page:eq(' + index + ')');

                            if ($existing.length != 0) {
                                framework7.pageRemoveCallback(view, $existing[0], '');
                                $existing.remove();
                            }
                        }

                        return originalLoad(view, options);
                    };
                }
            }
        }
    };
})(this);

emilycestmoi avatar Nov 16 '18 04:11 emilycestmoi

Im using v2, is this applicable?

pluckannfeel avatar Nov 19 '18 02:11 pluckannfeel