Skip to content

Commit 3b2bb97

Browse files
committed
wip(card-list): fixup implementation of isDragging
1 parent 95ff17e commit 3b2bb97

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

packages/angular-skyhook-card-list/src/card-renderer.directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ export class CardRendererDirective<Data> implements OnInit, OnDestroy {
116116
) {
117117
}
118118

119-
sameIds(data: Data, other: DraggedItem<Data>) {
119+
sameIds = (data: Data, other: DraggedItem<Data>) => {
120120
return data && other.data && this.spec.trackBy(data) === this.spec.trackBy(other.data);
121121
}
122122

123-
isDragging(item: DraggedItem<Data>) {
123+
isDragging(item: DraggedItem<Data> | null) {
124124
const isD = this.spec && this.spec.isDragging || this.sameIds;
125125
return item && isD(this.data, item) || false;
126126
}

packages/angular-skyhook-card-list/src/ngrx-helpers.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export interface ConfigureSpec<D> {
4444
getList: (listId: any) => Observable<Iterable<D>>;
4545
canDrag?: (data: D, listId: any) => boolean;
4646
canDrop?: (item: DraggedItem<D>) => boolean;
47-
isDragging?: (self: D, other: DraggedItem<D>) => boolean;
47+
isDragging?: (ground: D, inFlight: DraggedItem<D>) => boolean;
4848
// copy?: (item: DraggedItem<T>) => boolean | T;
4949
// clone?: (data: T) => T;
5050
}
@@ -54,17 +54,19 @@ export class NgRxSortable<D> implements SortableSpec<D> {
5454
public getList!: (listId: any) => Observable<Iterable<D>>;
5555
public canDrag?: (data: D, listId: any) => boolean;
5656
public canDrop?: (item: DraggedItem<D>) => boolean;
57+
public isDragging?: (ground: D, inFlight: DraggedItem<D>) => boolean;
5758

5859
/**
5960
* @param store An @ngrx store instance.
6061
* @param actionType The type in your own @ngrx/store `ActionTypes` enum you want the sortable actions to use.
6162
* @param configure You must provide `trackBy` and `getList` functions here. Hopefully your `getList` will select from the store you passed!
6263
* */
63-
constructor(private store: Dispatcher, public actionType: string, configure: ConfigureSpec<D>) {
64-
this.trackBy = configure.trackBy;
65-
this.getList = configure.getList;
66-
this.canDrag = configure.canDrag;
67-
this.canDrop = configure.canDrop;
64+
constructor(protected store: Dispatcher, public actionType: string, configure: ConfigureSpec<D>) {
65+
if (configure.trackBy) this.trackBy = configure.trackBy;
66+
if (configure.getList) this.getList = configure.getList;
67+
if (configure.canDrag) this.canDrag = configure.canDrag;
68+
if (configure.canDrop) this.canDrop = configure.canDrop;
69+
if (configure.isDragging) this.isDragging = configure.isDragging;
6870
}
6971

7072
// We now implement the SortableSpec interface by dispatching actions

packages/angular-skyhook-card-list/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface SortableSpec<Data, Type = string|symbol> {
55
getList: (listId: any) => Observable<Iterable<Data> | undefined>;
66
canDrag?: (data: Data, listId: any) => boolean;
77
canDrop?: (item: DraggedItem<Data, Type>) => boolean;
8-
isDragging?: (self: Data, other: DraggedItem<Data, Type>) => boolean;
8+
isDragging?: (ground: Data, inFlight: DraggedItem<Data, Type>) => boolean;
99
beginDrag?: (item: DraggedItem<Data, Type>) => void;
1010
hover?: (item: DraggedItem<Data, Type>) => void;
1111
drop?: (item: DraggedItem<Data, Type>) => void;

0 commit comments

Comments
 (0)