diff --git a/src/state/create-store.js b/src/state/create-store.js index d8282f03a7..e86c5e1d31 100644 --- a/src/state/create-store.js +++ b/src/state/create-store.js @@ -41,7 +41,7 @@ export default ({ // > uncomment to use // debugging logger - // require('./debug-middleware/log-middleware').default, + require('./debug-middleware/log-middleware').default, // debugging timer // require('./debug-middleware/timing-middleware').default, // average action timer diff --git a/src/state/dimension-marshal/collector.js b/src/state/dimension-marshal/collector.js index ba4fb80fe7..8e29a69195 100644 --- a/src/state/dimension-marshal/collector.js +++ b/src/state/dimension-marshal/collector.js @@ -169,7 +169,7 @@ export default ({ critical: includeCritical ? critical : null, }); timings.finish('Bulk dimension publish'); - }, 0); + }, 200); frameId = null; }); }); diff --git a/src/state/middleware/auto-scroll.js b/src/state/middleware/auto-scroll.js index 883bafb603..53ea92c219 100644 --- a/src/state/middleware/auto-scroll.js +++ b/src/state/middleware/auto-scroll.js @@ -7,7 +7,6 @@ import type { AutoScroller } from '../auto-scroller/auto-scroller-types'; import type { DimensionMarshal } from '../../state/dimension-marshal/dimension-marshal-types'; import { move } from '../action-creators'; import scrollWindow from '../../view/window/scroll-window'; -import isDragEnding from './util/is-drag-ending'; import type { DraggableId, @@ -32,7 +31,8 @@ export default (getMarshal: () => DimensionMarshal) => const shouldCancel = (action: Action) => // Need to cancel any pending auto scrolling when drag is ending - isDragEnding(action) || + action.type === 'CANCEL' || + action.type === 'DROP' || // A new bulk collection is starting - cancel any pending auto scrolls action.type === 'BULK_COLLECTION_STARTING'; diff --git a/src/state/middleware/dimension-marshal-stopper.js b/src/state/middleware/dimension-marshal-stopper.js index f8b6b39ce9..9ef54a27e6 100644 --- a/src/state/middleware/dimension-marshal-stopper.js +++ b/src/state/middleware/dimension-marshal-stopper.js @@ -1,11 +1,11 @@ // @flow -import isDragEnding from './util/is-drag-ending'; import type { Action } from '../../types'; import type { DimensionMarshal } from '../dimension-marshal/dimension-marshal-types'; export default (getMarshal: () => DimensionMarshal) => () => (next: (Action) => mixed) => (action: Action): mixed => { - if (isDragEnding(action)) { + // Not stopping a bulk collection on a 'DROP' as we want that collection to continue + if (action.type === 'DROP_COMPLETE' || action.type === 'CLEAN' || action.type === 'DROP_ANIMATE') { const marshal: DimensionMarshal = getMarshal(); marshal.stopPublishing(); } diff --git a/src/state/middleware/util/is-drag-ending.js b/src/state/middleware/util/is-drag-ending.js deleted file mode 100644 index 7acc5623b9..0000000000 --- a/src/state/middleware/util/is-drag-ending.js +++ /dev/null @@ -1,5 +0,0 @@ -// @flow -import type { Action } from '../../../types'; - -export default (action: Action): boolean => - action.type === 'CLEAN' || action.type === 'DROP'; diff --git a/test/unit/state/scroll-viewport.spec.js b/test/unit/state/scroll-viewport.spec.js index c1e077b698..5fda4bb130 100644 --- a/test/unit/state/scroll-viewport.spec.js +++ b/test/unit/state/scroll-viewport.spec.js @@ -1,7 +1,7 @@ // @flow import { getRect, type Position, type Rect } from 'css-box-model'; import type { Viewport } from '../../../src/types'; -import { add, negate } from '../../../src/state/position'; +import { add, negate, subtract } from '../../../src/state/position'; import scrollViewport from '../../../src/state/scroll-viewport'; import { offsetByPosition } from '../../../src/state/spacing'; @@ -51,7 +51,7 @@ it('should update the window details scroll', () => { expect(updated).toEqual(expected); }); -it('should correctly update scroll across multiple movements', () => { +it('should correctly update scroll across multiple movements (forwards)', () => { const original: Rect = getRect({ top: 0, left: 0, @@ -59,12 +59,14 @@ it('should correctly update scroll across multiple movements', () => { bottom: 100, }); + const max: Position = { x: 200, y: 200 }; + let lastViewport: Viewport = { frame: original, scroll: { initial: origin, current: origin, - max: { x: 1000, y: 1000 }, + max, diff: { value: origin, displacement: origin, @@ -73,8 +75,9 @@ it('should correctly update scroll across multiple movements', () => { }; let lastScroll: Position = origin; + let runCount: number = 0; - Array.from({ length: 5 }).forEach(() => { + while (lastScroll.y < max.y && lastScroll.x < max.x) { const newScroll: Position = add(lastScroll, { x: 10, y: 20 }); const updated: Viewport = scrollViewport(lastViewport, newScroll); @@ -83,7 +86,7 @@ it('should correctly update scroll across multiple movements', () => { scroll: { initial: origin, current: newScroll, - max: { x: 1000, y: 1000 }, + max, diff: { value: newScroll, displacement: negate(newScroll), @@ -96,5 +99,65 @@ it('should correctly update scroll across multiple movements', () => { lastScroll = newScroll; lastViewport = updated; + runCount++; + }; + + // Simply asserting our loop ran a few times + expect(runCount).toBeGreaterThan(2); +}); + +it('should correctly update scroll across multiple movements (backwards)', () => { + const original: Rect = getRect({ + top: 0, + left: 0, + right: 100, + bottom: 100, }); + + const max: Position = { x: 200, y: 200 }; + + let lastViewport: Viewport = { + frame: original, + scroll: { + initial: max, + current: max, + max, + diff: { + value: origin, + displacement: origin, + }, + }, + }; + + let lastScroll: Position = max; + let runCount: number = 0; + while (lastScroll.y > 0 && lastScroll.x > 0) { + const newScroll: Position = subtract(lastScroll, { x: 10, y: 20 }); + const updated: Viewport = scrollViewport(lastViewport, newScroll); + + const diff: Position = subtract(newScroll, lastViewport.scroll.initial); + + const expected: Viewport = { + frame: getRect(offsetByPosition(original, newScroll)), + scroll: { + initial: max, + current: newScroll, + max, + diff: { + value: diff, + displacement: negate(diff), + }, + }, + }; + expect(updated).toEqual(expected); + expect(updated.frame.top).toEqual(newScroll.y); + expect(updated.frame.left).toEqual(newScroll.x); + + lastScroll = newScroll; + lastViewport = updated; + runCount++; + } + + // Simply asserting our loop ran a few times + expect(runCount).toBeGreaterThan(2); });