Skip to content

Commit 46e8e26

Browse files
committed
refactor(default-layout): drop MutationObserver, add minimizedChange event
1 parent d77180f commit 46e8e26

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

src/app/containers/default-layout/default-layout.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
</ul>
5050
</app-header>
5151
<div class="app-body">
52-
<app-sidebar [fixed]="true" [display]="'lg'">
53-
<app-sidebar-nav [navItems]="navItems" [perfectScrollbar] [disabled]="sidebarMinimized"></app-sidebar-nav>
52+
<app-sidebar #appSidebar [fixed]="true" [display]="'lg'" [minimized]="sidebarMinimized" (minimizedChange)="toggleMinimize($event)">
53+
<app-sidebar-nav [navItems]="navItems" [perfectScrollbar] [disabled]="appSidebar.minimized"></app-sidebar-nav>
5454
<app-sidebar-minimizer></app-sidebar-minimizer>
5555
</app-sidebar>
5656
<!-- Main content -->
@@ -83,7 +83,7 @@
8383
<router-outlet></router-outlet>
8484
</div><!-- /.container-fluid -->
8585
</main>
86-
<app-aside [fixed]="true" [display]="false">
86+
<app-aside [fixed]="true" [display]="false" [ngClass]="'test'">
8787
<tabset>
8888
<tab>
8989
<ng-template tabHeading><i class="icon-list"></i></ng-template>
Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
import { Component, OnDestroy, Inject } from '@angular/core';
2-
import { DOCUMENT } from '@angular/common';
1+
import {Component } from '@angular/core';
32
import { navItems } from '../../_nav';
43

5-
64
@Component({
75
selector: 'app-dashboard',
86
templateUrl: './default-layout.component.html'
97
})
10-
export class DefaultLayoutComponent implements OnDestroy {
8+
export class DefaultLayoutComponent {
9+
public sidebarMinimized = false;
1110
public navItems = navItems;
12-
public sidebarMinimized = true;
13-
private changes: MutationObserver;
14-
public element: HTMLElement;
15-
constructor(@Inject(DOCUMENT) _document?: any) {
16-
17-
this.changes = new MutationObserver((mutations) => {
18-
this.sidebarMinimized = _document.body.classList.contains('sidebar-minimized');
19-
});
20-
this.element = _document.body;
21-
this.changes.observe(<Element>this.element, {
22-
attributes: true,
23-
attributeFilter: ['class']
24-
});
25-
}
2611

27-
ngOnDestroy(): void {
28-
this.changes.disconnect();
12+
toggleMinimize(e) {
13+
this.sidebarMinimized = e;
14+
console.log('toggleMinimize', e, this.sidebarMinimized);
2915
}
3016
}

0 commit comments

Comments
 (0)