Various refactoring

This commit is contained in:
Geomitron
2020-03-03 21:48:41 -05:00
parent 442736205e
commit 4ebf2db650
34 changed files with 503 additions and 329 deletions

View File

@@ -0,0 +1,27 @@
import { RouteReuseStrategy, ActivatedRouteSnapshot, DetachedRouteHandle } from '@angular/router'
/**
* This makes each route with the 'reuse' data flag persist when not in focus.
*/
export class TabPersistStrategy extends RouteReuseStrategy {
private handles: { [path: string]: DetachedRouteHandle } = {}
shouldDetach(route: ActivatedRouteSnapshot) {
return route.data.shouldReuse || false
}
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle) {
if (route.data.shouldReuse) {
this.handles[route.routeConfig.path] = handle
}
}
shouldAttach(route: ActivatedRouteSnapshot) {
return !!route.routeConfig && !!this.handles[route.routeConfig.path]
}
retrieve(route: ActivatedRouteSnapshot) {
if (!route.routeConfig) return null
return this.handles[route.routeConfig.path]
}
shouldReuseRoute(future: ActivatedRouteSnapshot, _curr: ActivatedRouteSnapshot) {
return future.data.shouldReuse || false
}
}