app state

This commit is contained in:
nixa 2016-05-13 13:34:55 +03:00
parent e6be0e4519
commit 38e1c6cfa3
8 changed files with 62 additions and 57 deletions

View file

@ -1,7 +1,6 @@
import {Component} from '@angular/core';
import {Subscription} from "rxjs/Subscription";
import {ThemeGlobal} from "../../../theme";
import {AppState} from "../../../app.state";
@Component({
selector: 'content-top',
@ -10,16 +9,10 @@ import {ThemeGlobal} from "../../../theme";
})
export class ContentTop {
activePageTitle = '';
private _themeGlobalSubscription:Subscription;
constructor(private _themeGlobal:ThemeGlobal) {
this._themeGlobalSubscription = this._themeGlobal.getDataStream().subscribe((data) => {
this.activePageTitle = data['menu.activeLink'] != null ? data['menu.activeLink'].title : this.activePageTitle;
constructor(private _state:AppState) {
this._state.subscribe('menu.activeLink', (activeLink) => {
this.activePageTitle = activeLink.title;
});
}
ngOnDestroy() {
// prevent memory leak when component destroyed
this._themeGlobalSubscription.unsubscribe();
}
}

View file

@ -1,6 +1,6 @@
import {Component, ViewEncapsulation} from '@angular/core';
import {ThemeGlobal} from '../../../theme';
import {AppState} from '../../../app.state';
import {ProfilePicturePipe} from '../../pipes';
import {MsgCenter} from '../../components/msgCenter';
import {ScrollPosition} from '../../directives';
@ -18,12 +18,12 @@ export class PageTop {
isMenuCollapsed:boolean = false;
constructor(private _themeGlobal:ThemeGlobal) {
constructor(private _state:AppState) {
}
toggleMenu() {
this.isMenuCollapsed = !this.isMenuCollapsed;
this._themeGlobal.setData('menu.isCollapsed', this.isMenuCollapsed);
this._state.notifyDataChanged('menu.isCollapsed', this.isMenuCollapsed);
}
scrolledChanged(isScrolled) {

View file

@ -1,7 +1,8 @@
import {Component, ElementRef, HostListener, ViewEncapsulation} from '@angular/core';
import {Router} from '@angular/router-deprecated';
import {ThemeGlobal, layoutSizes} from '../../../theme';
import {AppState} from '../../../app.state';
import {layoutSizes} from '../../../theme';
import {SidebarService} from './sidebar.service';
// TODO: separate menu and sidebar
@ -33,7 +34,7 @@ export class Sidebar {
constructor(private _elementRef:ElementRef,
private _router:Router,
private _sidebarService:SidebarService,
private _themeGlobal:ThemeGlobal) {
private _state:AppState) {
}
@ -70,7 +71,7 @@ export class Sidebar {
menuCollapseStateChange(isCollapsed) {
this.isMenuCollapsed = isCollapsed;
this._themeGlobal.setData('menu.isCollapsed', this.isMenuCollapsed);
this._state.notifyDataChanged('menu.isCollapsed', this.isMenuCollapsed);
}
hoverItem($event) {
@ -123,6 +124,6 @@ export class Sidebar {
});
// notifies all subscribers
this._themeGlobal.setData('menu.activeLink', currentMenu);
this._state.notifyDataChanged('menu.activeLink', currentMenu);
}
}