framework7
framework7 copied to clipboard
[v3] stackPages needs a maximum
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();
}
}
@nolimits4web what do you think?
@ZanderBrown I think it can be useful, will add it to roadmap
@nolimits4web did this make it to V2?
@ZanderBrown no, let me mark it as v2 feature request
@emilynewsom, where did you put this hack of yours? what specific file
@nolimits4web is this applied in v3 already?
@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);
Im using v2, is this applicable?