Skip to content

Commit

Permalink
lets see how we go
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 7, 2018
1 parent 184696c commit 589ef1e
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/debug/timings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const flag: string = '__react-beautiful-dnd-debug-timings-hook__';
const isTimingsEnabled = (): boolean => Boolean(window[flag]);

// TEMP
// window[flag] = true;
window[flag] = true;

export const start = (key: string) => {
if (!isTimingsEnabled()) {
Expand Down
65 changes: 38 additions & 27 deletions src/state/action-creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,44 +85,56 @@ export const completeLift = (
},
});

export type PublishDraggableDimensionAction = {|
type: 'PUBLISH_DRAGGABLE_DIMENSION',
payload: DraggableDimension,
|}

export const publishDraggableDimension =
(dimension: DraggableDimension): PublishDraggableDimensionAction => ({
type: 'PUBLISH_DRAGGABLE_DIMENSION',
payload: dimension,
});

export type PublishDroppableDimensionAction = {|
type: 'PUBLISH_DROPPABLE_DIMENSION',
payload: DroppableDimension,
export type InitialPublishAction = {|
type: 'INITIAL_PUBLISH',
payload: {|
home: DroppableDimension,
draggable: DraggableDimension,
viewport: Viewport,
|}
|}

export const publishDroppableDimension =
(dimension: DroppableDimension): PublishDroppableDimensionAction => ({
type: 'PUBLISH_DROPPABLE_DIMENSION',
payload: dimension,
});
export const initialPublish = (
home: DroppableDimension,
draggable: DraggableDimension,
viewport: Viewport,
): InitialPublishAction => ({
type: 'INITIAL_PUBLISH',
payload: {
home,
draggable,
viewport,
},
});

export type BulkPublishDimensionsAction = {|
type: 'BULK_DIMENSION_PUBLISH',
export type BulkReplaceAction = {|
type: 'BULK_REPLACE',
payload: {|
droppables: DroppableDimension[],
draggables: DraggableDimension[],
viewport: Viewport,
replaceCritical: boolean,
|}
|}

export const bulkPublishDimensions = (
type BulkReplaceArgs = {|
droppables: DroppableDimension[],
draggables: DraggableDimension[],
): BulkPublishDimensionsAction => ({
type: 'BULK_DIMENSION_PUBLISH',
viewport: Viewport,
replaceCritical: boolean,
|}
export const bulkReplace = ({
droppables,
draggables,
viewport,
replaceCritical,
}: BulkReplaceArgs): BulkReplaceAction => ({
type: 'BULK_REPLACE',
payload: {
droppables,
draggables,
viewport,
replaceCritical,
},
});

Expand Down Expand Up @@ -522,9 +534,8 @@ export const lift = (id: DraggableId,
export type Action =
CompleteLiftAction |
RequestDimensionsAction |
PublishDraggableDimensionAction |
PublishDroppableDimensionAction |
BulkPublishDimensionsAction |
InitialPublishAction |
BulkPublishAction |
UpdateDroppableDimensionScrollAction |
UpdateDroppableDimensionIsEnabledAction |
MoveByWindowScrollAction |
Expand Down
21 changes: 15 additions & 6 deletions src/state/dimension-marshal/collector.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
import invariant from 'tiny-invariant';
import { type Position } from 'css-box-model';
import * as timings from '../../debug/timings';
import getViewport from '../../view/window/get-viewport';
import type {
DraggableId,
DroppableId,
Expand All @@ -9,6 +11,7 @@ import type {
DroppableDescriptor,
DraggableDescriptor,
ScrollOptions,
Viewport,
} from '../../types';
import type {
Entries,
Expand All @@ -34,7 +37,11 @@ type InternalOptions = {|

type Args = {|
getEntries: () => Entries,
publish: (droppables: DroppableDimension[], draggables: DraggableDimension[]) => void,
publish: (
droppables: DroppableDimension[],
draggables: DraggableDimension[],
viewport: Viewport,
) => void,
|}

const defaultOptions: InternalOptions = {
Expand All @@ -51,7 +58,7 @@ export default ({
let isQueued: boolean = false;
let isRunning: boolean = false;

const collectFromDOM = (options: InternalOptions): Collected => {
const collectFromDOM = (windowScroll: Position, options: InternalOptions): Collected => {
invariant(isActive, 'Should not collect when not active');
invariant(collection, 'Need collection options to pull from DOM');

Expand Down Expand Up @@ -109,10 +116,11 @@ export default ({

const droppableDimensions: DroppableDimension[] =
droppables.map((entry: DroppableEntry): DroppableDimension =>
entry.callbacks.getDimensionAndWatchScroll(scrollOptions));
entry.callbacks.getDimensionAndWatchScroll(windowScroll, scrollOptions));

const draggableDimensions: DraggableDimension[] =
draggables.map((entry: DraggableEntry): DraggableDimension => entry.getDimension());
draggables.map((entry: DraggableEntry): DraggableDimension =>
entry.getDimension(windowScroll));

// 4. Tell all the droppables to show their placeholders
droppables.forEach((entry: DroppableEntry) => entry.callbacks.showPlaceholder());
Expand All @@ -131,13 +139,14 @@ export default ({
// Perform DOM collection in next frame
frameId = requestAnimationFrame(() => {
timings.start('DOM collection');
const collected: Collected = collectFromDOM(options);
const viewport: Viewport = getViewport();
const collected: Collected = collectFromDOM(viewport.scroll, options);
timings.finish('DOM collection');

// Perform publish in next frame
frameId = requestAnimationFrame(() => {
timings.start('Bulk dimension publish');
publish(collected.droppables, collected.draggables);
publish(collected.droppables, collected.draggables, viewport);
timings.finish('Bulk dimension publish');

// TODO: what if publish caused collection?
Expand Down
11 changes: 9 additions & 2 deletions src/state/dimension-marshal/dimension-marshal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import type {
DroppableId,
State,
ScrollOptions,
Viewport,
} from '../../types';

export type GetDraggableDimensionFn = () => DraggableDimension;
export type GetDroppableDimensionFn = (options: ScrollOptions) => DroppableDimension;
export type GetDraggableDimensionFn = (windowScroll: Position) => DraggableDimension;
export type GetDroppableDimensionFn = (windowScroll: Position, options: ScrollOptions) => DroppableDimension;

export type DroppableCallbacks = {|
getDimensionAndWatchScroll: GetDroppableDimensionFn,
Expand Down Expand Up @@ -92,9 +93,15 @@ export type Callbacks = {|
cancel: () => void,
publishDraggable: (DraggableDimension) => void,
publishDroppable: (DroppableDimension) => void,
initialPublish: (
home: DroppableDimension,
draggable: DraggableDimension,
viewport: Viewport,
) => void,
bulkPublish: (
droppables: DroppableDimension[],
draggables: DraggableDimension[],
viewport: Viewport,
) => void,
updateDroppableScroll: (id: DroppableId, newScroll: Position) => void,
updateDroppableIsEnabled: (id: DroppableId, isEnabled: boolean) => void,
Expand Down
14 changes: 10 additions & 4 deletions src/state/dimension-marshal/dimension-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { type Position } from 'css-box-model';
import invariant from 'tiny-invariant';
import createCollector, { type Collector } from './collector';
// TODO: state folder reaching into view
import getViewport from '../../view/window/get-viewport';
import * as timings from '../../debug/timings';
import type {
DraggableId,
Expand All @@ -13,6 +15,7 @@ import type {
State as AppState,
Phase,
LiftRequest,
Viewport,
} from '../../types';
import type {
DimensionMarshal,
Expand Down Expand Up @@ -249,13 +252,16 @@ export default (callbacks: Callbacks) => {
},
};

const viewport: Viewport = getViewport();

// Get the minimum dimensions to start a drag
timings.start('initial collection and publish');
const home: DroppableDimension =
homeEntry.callbacks.getDimensionAndWatchScroll(request.scrollOptions);
const draggable: DraggableDimension = draggableEntry.getDimension();
callbacks.publishDroppable(home);
callbacks.publishDraggable(draggable);
homeEntry.callbacks.getDimensionAndWatchScroll(viewport.scroll, request.scrollOptions);
const draggable: DraggableDimension = draggableEntry.getDimension(viewport.scroll);
callbacks.initialPublish(home, draggable, viewport);
// callbacks.publishDroppable(home);
// callbacks.publishDraggable(draggable);
timings.finish('initial collection and publish');
};

Expand Down
Loading

0 comments on commit 589ef1e

Please sign in to comment.