Skip to content

Commit

Permalink
Editor: Optimize common dependencies bail-out (#16839)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth authored and gziolo committed Aug 29, 2019
1 parent e81e374 commit 4bd6146
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ const lastBlockSourceDependenciesByRegistry = new WeakMap;
*/
function* getBlocksWithSourcedAttributes( blocks ) {
const registry = yield getRegistry();
if ( ! lastBlockSourceDependenciesByRegistry.has( registry ) ) {
return blocks;
}

const blockSourceDependencies = lastBlockSourceDependenciesByRegistry.get( registry );

let workingBlocks = blocks;
for ( let i = 0; i < blocks.length; i++ ) {
Expand All @@ -66,11 +71,6 @@ function* getBlocksWithSourcedAttributes( blocks ) {
continue;
}

if ( ! lastBlockSourceDependenciesByRegistry.has( registry ) ) {
continue;
}

const blockSourceDependencies = lastBlockSourceDependenciesByRegistry.get( registry );
if ( ! blockSourceDependencies.has( sources[ schema.source ] ) ) {
continue;
}
Expand Down Expand Up @@ -136,13 +136,13 @@ function* resetLastBlockSourceDependencies( sourcesToUpdate = Object.values( sou
}

const registry = yield getRegistry();
if ( ! lastBlockSourceDependenciesByRegistry.has( registry ) ) {
lastBlockSourceDependenciesByRegistry.set( registry, new WeakMap );
}

for ( const source of sourcesToUpdate ) {
if ( ! lastBlockSourceDependenciesByRegistry.has( registry ) ) {
lastBlockSourceDependenciesByRegistry.set( registry, new WeakMap );
}
const lastBlockSourceDependencies = lastBlockSourceDependenciesByRegistry.get( registry );

const lastBlockSourceDependencies = lastBlockSourceDependenciesByRegistry.get( registry );
for ( const source of sourcesToUpdate ) {
const dependencies = yield* source.getDependencies();
lastBlockSourceDependencies.set( source, dependencies );
}
Expand Down

0 comments on commit 4bd6146

Please sign in to comment.