-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support stacks of a specific group (i.e: overlay stack per plugin)
fix: change overlay destroy order, first run hooks, then observable then destroy overlay component ref
- Loading branch information
Shlomi Assaf (shlassaf)
committed
Aug 23, 2016
1 parent
2c9bca5
commit 18acd51
Showing
4 changed files
with
94 additions
and
41 deletions.
There are no files selected for viewing
100 changes: 71 additions & 29 deletions
100
src/components/angular2-modal/models/dialog-ref-stack.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,91 @@ | ||
import { DialogRef } from './dialog-ref'; | ||
|
||
const BASKET_GROUP = {}; | ||
|
||
/** | ||
* A dumb stack implementation over an array. | ||
*/ | ||
export class DialogRefStack<T> { | ||
private _stack: DialogRef<T>[] = []; | ||
private _stack: DialogRef<T>[]; | ||
private _stackMap: Map<DialogRef<T>, any>; | ||
|
||
get length(): number { | ||
return this._stack.length; | ||
} | ||
|
||
push(dialogRef: DialogRef<T>): void { | ||
let idx = this._stack.indexOf(dialogRef); | ||
if (idx === -1) this._stack.push(dialogRef); | ||
} | ||
constructor() { | ||
this._stack = []; | ||
this._stackMap = new Map<DialogRef<T>, any>(); | ||
} | ||
|
||
/** | ||
* Push a DialogRef into the stack and manage it so when it's done | ||
* it will automatically kick itself out of the stack. | ||
* @param dialogRef | ||
*/ | ||
pushManaged(dialogRef: DialogRef<T>): void { | ||
this.push(dialogRef); | ||
push(dialogRef: DialogRef<T>, group?: any): void { | ||
if (this._stack.indexOf(dialogRef) === -1) { | ||
this._stack.push(dialogRef); | ||
this._stackMap.set(dialogRef, group || BASKET_GROUP); | ||
} | ||
} | ||
|
||
pop(): void { | ||
this._stack.pop(); | ||
} | ||
/** | ||
* Push a DialogRef into the stack and manage it so when it's done | ||
* it will automatically kick itself out of the stack. | ||
* @param dialogRef | ||
*/ | ||
pushManaged(dialogRef: DialogRef<T>, group?: any): void { | ||
this.push(dialogRef, group); | ||
dialogRef.onDestroy.subscribe(() => this.remove(dialogRef)); | ||
} | ||
|
||
/** | ||
* Remove a DialogRef from the stack. | ||
* @param dialogRef | ||
*/ | ||
remove(dialogRef: DialogRef<T>): void { | ||
let idx = this._stack.indexOf(dialogRef); | ||
if (idx > -1) this._stack.splice(idx, 1); | ||
pop(): DialogRef<T> { | ||
const dialogRef = this._stack.pop(); | ||
this._stackMap.delete(dialogRef); | ||
return dialogRef; | ||
} | ||
|
||
/** | ||
* Remove a DialogRef from the stack. | ||
* @param dialogRef | ||
*/ | ||
remove(dialogRef: DialogRef<T>): void { | ||
let idx = this.indexOf(dialogRef); | ||
if (idx > -1) { | ||
this._stack.splice(idx, 1); | ||
this._stackMap.delete(dialogRef); | ||
} | ||
} | ||
|
||
index(index: number): DialogRef<T> { | ||
return this._stack[index]; | ||
} | ||
|
||
index(index: number): DialogRef<T> { | ||
return this._stack[index]; | ||
} | ||
indexOf(dialogRef: DialogRef<T>): number { | ||
return this._stack.indexOf(dialogRef); | ||
} | ||
|
||
groupOf(dialogRef: DialogRef<T>): any { | ||
return this._stackMap.get(dialogRef); | ||
} | ||
|
||
indexOf(dialogRef: DialogRef<T>): number { | ||
return this._stack.indexOf(dialogRef); | ||
groupBy(group: any): DialogRef<T>[] { | ||
let arr = []; | ||
if (group) { | ||
this._stackMap.forEach( (value, key) => { | ||
if (value === group) { | ||
arr.push(key); | ||
} | ||
}); | ||
} | ||
return arr; | ||
} | ||
|
||
get length(): number { | ||
return this._stack.length; | ||
groupLength(group: any): number { | ||
let count = 0; | ||
if (group) { | ||
this._stackMap.forEach( (value, key) => { | ||
if (value === group) { | ||
count++; | ||
} | ||
}); | ||
} | ||
return count; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters