Skip to content

Commit 6bab95c

Browse files
committed
examples: more types pinned down on sources and targets
1 parent e5df40a commit 6bab95c

File tree

7 files changed

+22
-21
lines changed

7 files changed

+22
-21
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface BoxWithLocation {
2+
id: number;
3+
title: string;
4+
left: number;
5+
top: number;
6+
}

packages/examples/src/app/drag-layer/drag-container/drag-container.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnInit, OnDestroy } from '@angular/core';
22
import { SkyhookDndService } from 'angular-skyhook';
3-
import { DraggedItem } from '../dragged-item';
3+
import { BoxWithLocation } from '../BoxWithLocation';
44

55
@Component({
66
selector: 'app-drag-container',
@@ -24,7 +24,7 @@ export class DragContainerComponent implements OnInit, OnDestroy {
2424
position: 'relative',
2525
};
2626

27-
boxTarget = this.dnd.dropTarget<DraggedItem>('BOX', {
27+
boxTarget = this.dnd.dropTarget<BoxWithLocation>('BOX', {
2828
drop: (monitor) => {
2929
const delta = monitor.getDifferenceFromInitialOffset();
3030
const item = monitor.getItem();

packages/examples/src/app/drag-layer/draggable-box/draggable-box.component.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SkyhookDndService, DragPreviewOptions } from 'angular-skyhook';
33
import { getEmptyImage } from 'react-dnd-html5-backend';
44
import { map } from 'rxjs/operators';
55
import { ChangeDetectionStrategy } from '@angular/core';
6+
import { BoxWithLocation } from '../BoxWithLocation';
67

78
@Component({
89
selector: 'app-draggable-box',
@@ -15,14 +16,14 @@ import { ChangeDetectionStrategy } from '@angular/core';
1516
})
1617
export class DraggableBoxComponent {
1718

18-
@Input() id;
19-
@Input() title;
20-
@Input() left;
21-
@Input() top;
19+
@Input() id: number;
20+
@Input() title: string;
21+
@Input() left: number;
22+
@Input() top: number;
2223

23-
source = this.dnd.dragSource('BOX', {
24+
source = this.dnd.dragSource<BoxWithLocation>('BOX', {
2425
beginDrag: () => {
25-
const { id, title, left, top } = this;
26+
const { id, title, left, top } = this;
2627
return { id, title, left, top };
2728
}
2829
});

packages/examples/src/app/drag-layer/dragged-item.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/examples/src/app/xy-pad/cube.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ export class CubeComponent {
5656
@Input() x: number;
5757
@Input() y: number;
5858
@Output() endDrag = new EventEmitter<void>();
59-
source = this.dnd.dragSource('BOX', {
59+
source = this.dnd.dragSource<Spot>('BOX', {
6060
beginDrag: () => {
61-
let spot = { id: 123, x: this.x, y: this.y, fromCube: true } as Spot;
62-
return spot;
61+
return { id: 123, x: this.x, y: this.y, fromCube: true };
6362
},
6463
endDrag: (monitor) => {
6564
this.endDrag.emit();

packages/examples/src/app/xy-pad/custom-drag-layer/custom-drag-layer.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Rect, alongEdge, plus, minus, clone, fmap } from '../vectors';
99

1010
interface Collected {
1111
item: Spot;
12-
itemType: string|symbol;
12+
itemType: string | symbol;
1313
isDragging: boolean;
1414
initialOffset: Offset;
1515
currentOffset: Offset;
@@ -39,7 +39,7 @@ interface Collected {
3939
</ng-container>
4040
`,
4141
changeDetection: ChangeDetectionStrategy.OnPush,
42-
styleUrls: ['./custom-drag-layer.component.scss']
42+
styleUrls: ['./custom-drag-layer.component.scss']
4343
})
4444
export class CustomDragLayerComponent {
4545

@@ -54,7 +54,7 @@ export class CustomDragLayerComponent {
5454

5555
rect: Rect = { x: 0, y: 0, width: 0, height: 0 };
5656

57-
dragLayer = this.dnd.dragLayer();
57+
dragLayer = this.dnd.dragLayer<Spot>();
5858

5959
collect$ = this.dragLayer.listen(monitor => {
6060
this.setWindowRelativeOffset();
@@ -133,7 +133,7 @@ export class CustomDragLayerComponent {
133133
};
134134
}
135135

136-
let {x, y} = this.getXY(item, initialOffset, currentOffset, true);
136+
let { x, y } = this.getXY(item, initialOffset, currentOffset, true);
137137
const transform = `translate3d(${x}px, ${y}px, 0)`;
138138
return {
139139
transform,

packages/examples/src/app/xy-pad/draggable-box/draggable-box.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class DraggableBoxComponent {
3838
@Input() spot: Spot;
3939
@Output() endDrag = new EventEmitter<{ spot: Spot }>();
4040

41-
source = this.dnd.dragSource('BOX', {
41+
source = this.dnd.dragSource<Spot>('BOX', {
4242
beginDrag: () => {
4343
return this.spot;
4444
},

0 commit comments

Comments
 (0)