Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Update to fix issue with ngFor not working correctly. Change to use .…
Browse files Browse the repository at this point in the history
…emit rather than .next for EventEmitter. Correctly implement OnDestroy method. Closes #33
  • Loading branch information
BTMorton committed Jan 5, 2016
1 parent d9171af commit 0bc89b0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ var PATHS = {
'bower_components/bootstrap/dist/css/bootstrap.min.css',
'bower_components/bootstrap/dist/css/bootstrap-theme.min.css',
'node_modules/angular2/bundles/angular2.min.js',
'node_modules/angular2/bundles/angular2-polyfills.min.js',
'node_modules/systemjs/dist/system.js',
'node_modules/systemjs/dist/system-polyfills.js',
'node_modules/es6-shim/es6-shim.min.js',
'node_modules/reflect-metadata/Reflect.js'
'node_modules/reflect-metadata/Reflect.js',
'node_modules/rxjs/bundles/Rx.min.js'
],
rx: 'node_modules/rxjs/**/*.js',
typings: [
Expand Down
6 changes: 3 additions & 3 deletions src/NgGrid.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementRef, Renderer, EventEmitter, DynamicComponentLoader, KeyValueDiffers, OnInit, DoCheck } from 'angular2/core';
import { ElementRef, Renderer, EventEmitter, DynamicComponentLoader, KeyValueDiffers, OnInit, OnDestroy, DoCheck } from 'angular2/core';
export declare class NgGrid implements OnInit, DoCheck {
private _differs;
private _ngEl;
Expand Down Expand Up @@ -95,7 +95,7 @@ export declare class NgGrid implements OnInit, DoCheck {
private _getItemFromPosition(position);
private _createPlaceholder(pos, dims);
}
export declare class NgGridItem implements OnInit {
export declare class NgGridItem implements OnInit, OnDestroy {
private _ngEl;
private _renderer;
private _ngGrid;
Expand Down Expand Up @@ -137,7 +137,7 @@ export declare class NgGridItem implements OnInit {
canDrag(e: any): boolean;
canResize(e: any): string;
onMouseMove(e: any): void;
onDestroy(): void;
ngOnDestroy(): void;
getElement(): ElementRef;
getDragHandle(): string;
getResizeHandle(): string;
Expand Down
34 changes: 17 additions & 17 deletions src/NgGrid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, View, Directive, ElementRef, Renderer, EventEmitter, DynamicComponentLoader, Host, ViewEncapsulation, Type, ComponentRef, KeyValueDiffer, KeyValueDiffers, OnInit, DoCheck } from 'angular2/core';
import { Component, View, Directive, ElementRef, Renderer, EventEmitter, DynamicComponentLoader, Host, ViewEncapsulation, Type, ComponentRef, KeyValueDiffer, KeyValueDiffers, OnInit, OnDestroy, DoCheck } from 'angular2/core';

@Directive({
selector: '[ngGrid]',
Expand Down Expand Up @@ -372,8 +372,8 @@ export class NgGrid implements OnInit, DoCheck {
this._createPlaceholder(item.getGridPosition(), item.getSize());
this.isResizing = true;

this.resizeStart.next(item);
item.resizeStart.next(item.getDimensions());
this.resizeStart.emit(item);
item.resizeStart.emit(item.getDimensions());
}
}

Expand All @@ -391,8 +391,8 @@ export class NgGrid implements OnInit, DoCheck {
this._createPlaceholder(item.getGridPosition(), item.getSize());
this.isDragging = true;

this.dragStart.next(item);
item.dragStart.next(item.getPosition());
this.dragStart.emit(item);
item.dragStart.emit(item.getPosition());
}
}

Expand Down Expand Up @@ -444,8 +444,8 @@ export class NgGrid implements OnInit, DoCheck {
this._draggingItem.setPosition(newL, newT);
}

this.drag.next(this._draggingItem);
this._draggingItem.drag.next(this._draggingItem.getPosition());
this.drag.emit(this._draggingItem);
this._draggingItem.drag.emit(this._draggingItem.getPosition());
}
}

Expand Down Expand Up @@ -490,8 +490,8 @@ export class NgGrid implements OnInit, DoCheck {
if (this._resizeDirection == 'height') bigGrid.x = iGridPos.col + itemSize.x;
if (this._resizeDirection == 'width') bigGrid.y = iGridPos.row + itemSize.y;

this.resize.next(this._resizingItem);
this._resizingItem.resize.next(this._resizingItem.getDimensions());
this.resize.emit(this._resizingItem);
this._resizingItem.resize.emit(this._resizingItem.getDimensions());
}
}

Expand Down Expand Up @@ -519,8 +519,8 @@ export class NgGrid implements OnInit, DoCheck {
this._cascadeGrid();

this._draggingItem.stopMoving();
this._draggingItem.dragStop.next(this._draggingItem.getPosition);
this.dragStop.next(this._draggingItem);
this._draggingItem.dragStop.emit(this._draggingItem.getPosition);
this.dragStop.emit(this._draggingItem);
this._draggingItem = null;
this._posOffset = null;
this._placeholderRef.dispose();
Expand All @@ -539,8 +539,8 @@ export class NgGrid implements OnInit, DoCheck {
this._cascadeGrid();

this._resizingItem.stopMoving();
this._resizingItem.resizeStop.next(this._resizingItem.getDimensions());
this.resizeStop.next(this._resizingItem);
this._resizingItem.resizeStop.emit(this._resizingItem.getDimensions());
this.resizeStop.emit(this._resizingItem);
this._resizingItem = null;
this._resizeDirection = null;
this._placeholderRef.dispose();
Expand Down Expand Up @@ -909,7 +909,7 @@ export class NgGrid implements OnInit, DoCheck {
inputs: [ 'config: ngGridItem', 'gridPosition: ngGridPosition', 'gridSize: ngGridSize' ],
outputs: ['itemChange', 'dragStart', 'drag', 'dragStop', 'resizeStart', 'resize', 'resizeStop']
})
export class NgGridItem implements OnInit {
export class NgGridItem implements OnInit, OnDestroy {
// Event Emitters
public itemChange: EventEmitter<any> = new EventEmitter();
public dragStart: EventEmitter<any> = new EventEmitter();
Expand Down Expand Up @@ -1044,7 +1044,7 @@ export class NgGridItem implements OnInit {
}
}

public onDestroy(): void {
public ngOnDestroy(): void {
if (this._added) this._ngGrid.removeItem(this);
}

Expand Down Expand Up @@ -1100,7 +1100,7 @@ export class NgGridItem implements OnInit {
this.gridSize = { 'x': this._sizex, 'y': this._sizey };
this._recalculateDimensions();

this.itemChange.next({'col': this._col, 'row': this._row, 'sizex': this._sizex, 'sizey': this._sizey});
this.itemChange.emit({'col': this._col, 'row': this._row, 'sizex': this._sizex, 'sizey': this._sizey});
}

public setGridPosition(col: number, row: number): void {
Expand All @@ -1110,7 +1110,7 @@ export class NgGridItem implements OnInit {

this._recalculatePosition();

this.itemChange.next({'col': this._col, 'row': this._row, 'sizex': this._sizex, 'sizey': this._sizey});
this.itemChange.emit({'col': this._col, 'row': this._row, 'sizex': this._sizex, 'sizey': this._sizey});
}

public setPosition(x: number, y: number): void {
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, View, Self, Query, QueryList, ViewEncapsulation, enableProdMode } from 'angular2/core';
import { Component, View, ViewEncapsulation, enableProdMode } from 'angular2/core';
import { CORE_DIRECTIVES, NgStyle, FORM_DIRECTIVES } from 'angular2/common';
import { bootstrap } from 'angular2/platform/browser';
import { NgGrid, NgGridItem } from "./NgGrid";
Expand Down
6 changes: 2 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<title>Angular 2 Grid Demo</title>
<link rel="stylesheet" href="lib/bootstrap.min.css" />
<script src="lib/es6-shim.min.js"></script>
<script src="lib/angular2-polyfills.min.js"></script>
<script src="lib/system.js"></script>
<script src="lib/Reflect.js"></script>
<script src="lib/Rx.min.js"></script>
<script src="lib/angular2.min.js"></script>
</head>
<body>
Expand All @@ -17,9 +18,6 @@
packages: {
'angular2': {
defaultExtension: false
},
'rxjs': {
defaultExtension: false
}
}
});
Expand Down

0 comments on commit 0bc89b0

Please sign in to comment.