Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 3, 2018
1 parent 6c7dad0 commit c8e2c79
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
29 changes: 25 additions & 4 deletions src/state/dimension-marshal/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
DraggableDimension,
DroppableDimension,
ScrollOptions,
Collection,
} from '../../types';
import type { ToBeCollected } from './dimension-marshal-types';

Expand All @@ -28,6 +29,13 @@ export type Collector = {|
collect: () => void,
|}

type CollectionOptions = {|
exclude: {
draggableId: DraggableId,
droppableId: DroppableId,
},
|}

export default ({
publish,
getDraggable,
Expand All @@ -39,17 +47,21 @@ export default ({
let isQueued: boolean = false;
let isRunning: boolean = false;

const collectFromDOM = (toBeCollected: ToBeCollected): Collected => {
const collectFromDOM = (toBeCollected: ToBeCollected, options?: CollectionOptions): Collected => {
invariant(isActive, 'Should not collect when not active');

const droppables: DroppableDimension[] = toBeCollected.droppables
.filter((id: DroppableId): boolean => Boolean(options && options.exclude.droppableId === id))
.map((id: DroppableId): DroppableDimension => getDroppable(id));

const draggables: DraggableDimension[] = toBeCollected.draggables
.filter((id: DraggableId): boolean => Boolean(options && options.exclude.draggableId === id))
.map((id: DraggableId): DraggableDimension => getDraggable(id));

return { draggables, droppables };
};

const run = () => {
const run = (options?: CollectionOptions) => {
invariant(isRunning, 'Cannot start a new run when a run is already occurring');

isRunning = true;
Expand All @@ -58,7 +70,7 @@ export default ({
frameId = requestAnimationFrame(() => {
timings.start('DOM collection');
const toBeCollected: ToBeCollected = getToBeCollected();
const collected: Collected = collectFromDOM(toBeCollected);
const collected: Collected = collectFromDOM(toBeCollected, options);
timings.finish('DOM collection');

// Perform publish in next frame
Expand All @@ -80,9 +92,18 @@ export default ({
});
};

const start = () => {
const start = (collection: Collection) => {
invariant(!isActive, 'Collector has already been started');
isActive = true;

// Start a collection - but there is no need to collect the
// critical dimensions as they have already been collected
run({
exclude: {
draggableId: collection.critical.draggable.descriptor.id,
droppableId: collection.critical.droppable.descriptor.id,
},
});
};

const collect = () => {
Expand Down
8 changes: 8 additions & 0 deletions src/state/dimension-marshal/dimension-marshal-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export type ToBeCollected = {|
droppables: DroppableId[],
|}

export type Collection = {|
scrollOptions: ScrollOptions,
critical: {|
draggable: DraggableDescriptor,
droppable: DroppableDescriptor,
|}
|}

export type DimensionMarshal = {|
// Draggable
registerDraggable: (descriptor: DraggableDescriptor,
Expand Down
13 changes: 4 additions & 9 deletions src/state/dimension-marshal/dimension-marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,9 @@ import type {
DraggableEntry,
DroppableEntryMap,
DraggableEntryMap,
Collection,
} from './dimension-marshal-types';

type Collection = {|
scrollOptions: ScrollOptions,
critical: {|
draggable: DraggableDescriptor,
droppable: DroppableDescriptor,
|}
|}

type Entries = {|
droppables: DroppableEntryMap,
draggables: DraggableEntryMap,
Expand Down Expand Up @@ -85,16 +78,18 @@ export default (callbacks: Callbacks) => {
const collector: Collector = createCollector({
publish: callbacks.bulkPublish,
getDraggable: (id: DraggableId): DraggableDimension => {
invariant(collection);
const entry: ?DraggableEntry = entries.draggables[id];
invariant(entry);

return entry.getDimension();
},
getDroppable: (id: DroppableId): DroppableDimension => {
invariant(collection);
const entry: ?DroppableEntry = entries.droppables[id];
invariant(entry);

return entry.callbacks.getDimension();
return entry.callbacks.getDimension(collection.scrollOptions);
},
getToBeCollected,
});
Expand Down

0 comments on commit c8e2c79

Please sign in to comment.