Skip to content

Commit

Permalink
Revert perf optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 5, 2022
1 parent 4b480c6 commit 5013124
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 37 deletions.
8 changes: 4 additions & 4 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1191,10 +1191,6 @@ _Parameters_

Action that hides the insertion point.

_Returns_

- `Object`: Action object.

### insertAfterBlock

Action that inserts an empty block after a given block.
Expand Down Expand Up @@ -1516,6 +1512,10 @@ _Parameters_
- _index_ `?number`: Index at which block should be inserted.
- _\_\_unstableOptions_ `Object`: Whether or not to show an inserter button.

_Returns_

- `Object`: Action object.

### startDraggingBlocks

Returns an action object used in signalling that the user has begun to drag blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export function useInBetweenInserter() {

showInsertionPoint( rootClientId, index, {
__unstableWithInserter: true,
delay: 500,
} );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ function InsertionPointPopover( {
...( ! isVertical ? horizontalLine.rest : verticalLine.rest ),
opacity: 1,
borderRadius: '2px',
transition: { delay: isInserterShown ? 0.1 : 0, type: 'tween' },
transition: { delay: isInserterShown ? 0.5 : 0, type: 'tween' },
},
hover: {
...( ! isVertical ? horizontalLine.hover : verticalLine.hover ),
opacity: 1,
borderRadius: '2px',
transition: { delay: 0.1, type: 'tween' },
transition: { delay: 0.5, type: 'tween' },
},
};

Expand All @@ -165,7 +165,7 @@ function InsertionPointPopover( {
},
rest: {
scale: 1,
transition: { type: 'tween' },
transition: { delay: 0.4, type: 'tween' },
},
};

Expand Down
44 changes: 15 additions & 29 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,49 +621,35 @@ export const insertBlocks =
}
};

const delayedInsertionPointCalls = new WeakMap();

/**
* Action that shows the insertion point.
*
* @param {?string} rootClientId Optional root client ID of block list on
* which to insert.
* @param {?number} index Index at which block should be inserted.
* @param {Object} __unstableOptions Whether or not to show an inserter button.
*
* @return {Object} Action object.
*/
export const showInsertionPoint =
( rootClientId, index, __unstableOptions = {} ) =>
( { dispatch, registry } ) => {
const previousCall = delayedInsertionPointCalls.get( registry );
if ( previousCall ) {
clearTimeout( previousCall );
}
const { __unstableWithInserter, delay } = __unstableOptions;
delayedInsertionPointCalls.set(
registry,
setTimeout( () => {
dispatch( {
type: 'SHOW_INSERTION_POINT',
rootClientId,
index,
__unstableWithInserter,
} );
}, delay )
);
export function showInsertionPoint(
rootClientId,
index,
__unstableOptions = {}
) {
const { __unstableWithInserter } = __unstableOptions;
return {
type: 'SHOW_INSERTION_POINT',
rootClientId,
index,
__unstableWithInserter,
};

}
/**
* Action that hides the insertion point.
*
* @return {Object} Action object.
*/
export const hideInsertionPoint =
() =>
( { select, dispatch, registry } ) => {
const previousCall = delayedInsertionPointCalls.get( registry );
if ( previousCall ) {
clearTimeout( previousCall );
}
( { select, dispatch } ) => {
if ( ! select.isBlockInsertionPointVisible() ) {
return;
}
Expand Down

0 comments on commit 5013124

Please sign in to comment.