Skip to content

Commit f97738f

Browse files
committed
fix(core): schedule a reconnect() call to match react-dnd's behaviour
Not completely sure why this is necessary, but they do it. I think if a component changes as a result of a new listen() value being emitted, and requires reconnecting as a result, this will catch the new DOM element.
1 parent 72bcb2d commit f97738f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/core/src/internal/connection-factory.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,14 @@ export class Connection<TMonitor extends DragSourceMonitor | DropTargetMonitor,
119119
// this schedules a single batch change detection run after all the listeners have heard their newest value
120120
// thus all changes resulting from subscriptions to this are caught by the
121121
// change detector.
122-
scheduleMicroTaskAfter(this.skyhookZone)
122+
scheduleMicroTaskAfter(this.skyhookZone, this.onUpdate)
123123
);
124124
}
125125

126+
private onUpdate = () => {
127+
this.handlerConnector.reconnect();
128+
};
129+
126130
connect(fn: (connector: TConnector) => void): Subscription {
127131
const subscription = this.resolvedType$.pipe(take(1)).subscribe(() => {
128132
// must run inside skyhookZone, so things like timers firing after a long hover with touch backend

packages/core/src/internal/scheduleMicroTaskAfter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,31 @@ import { Observable, TeardownLogic, Subscriber, Operator } from 'rxjs';
88
* processing all the listeners and are ready for Angular to perform change detection.
99
*/
1010

11-
export function scheduleMicroTaskAfter<T>(zone: Zone) {
11+
export function scheduleMicroTaskAfter<T>(zone: Zone, uTask?: () => void) {
1212
return (source: Observable<T>): Observable<T> => {
13-
return source.lift(new RunInZoneOperator(zone));
13+
return source.lift(new RunInZoneOperator(zone, uTask));
1414
};
1515
}
1616

1717
/**
1818
* @ignore
1919
*/
2020
export class ZoneSubscriber<T> extends Subscriber<T> {
21-
constructor(destination: Subscriber<T>, private zone: Zone) {
21+
constructor(destination: Subscriber<T>, private zone: Zone, private uTask: () => void = (() => {})) {
2222
super(destination);
2323
}
2424
protected _next(val: T) {
2525
this.destination.next && this.destination.next(val);
26-
this.zone.scheduleMicroTask('ZoneSubscriber', () => { });
26+
this.zone.scheduleMicroTask('ZoneSubscriber', this.uTask);
2727
}
2828
}
2929

3030
/**
3131
* @ignore
3232
*/
3333
export class RunInZoneOperator<T, R> implements Operator<T, R> {
34-
constructor(private zone: Zone) { }
34+
constructor(private zone: Zone, private uTask?: () => void) { }
3535
call(subscriber: Subscriber<R>, source: any): TeardownLogic {
36-
return source.subscribe(new ZoneSubscriber(subscriber, this.zone));
36+
return source.subscribe(new ZoneSubscriber(subscriber, this.zone, this.uTask));
3737
}
3838
}

0 commit comments

Comments
 (0)