Skip to content

Commit

Permalink
Cleanup and optimize blocks change
Browse files Browse the repository at this point in the history
  • Loading branch information
Tug committed Nov 7, 2018
1 parent e4826ec commit 1a2b13c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/app/App.js
Expand Up @@ -5,17 +5,15 @@ import '../globals';

import React from 'react';
import { Provider } from 'react-redux';
import { setupStore, html2State } from '../store';
import { type BlockType, setupStore, html2State } from '../store';
import AppContainer from './AppContainer';
import { Store } from 'redux';
import { withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { BlockEdit } from '@wordpress/editor';

import initialHtml from './initial-html';


type PropsType = {
onResetBlocks: Array<BlockType> => mixed,
initialData: string | Store,
};
type StateType = {
Expand Down Expand Up @@ -55,4 +53,4 @@ export default withDispatch( ( dispatch ) => {
return {
onResetBlocks: resetBlocks,
};
} )( AppProvider );
} )( AppProvider );
25 changes: 17 additions & 8 deletions src/app/AppContainer.js
Expand Up @@ -2,22 +2,31 @@
* @format */

import { connect } from 'react-redux';
import MainApp from './MainApp';
import { isEqual } from 'lodash';

import MainApp from './MainApp';
import { parse, serialize } from '@wordpress/blocks';
import { withDispatch, withSelect } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { BlockEdit } from '@wordpress/editor';
import RNReactNativeGutenbergBridge from 'react-native-gutenberg-bridge';

const mapStateToProps = ( state, ownProps ) => {
return {
blocks: ownProps.blocks.map( block => {
block.focused = ownProps.isBlockSelected( block.clientId );
return block;
} ),
refresh: ! ownProps.refresh
let blocks = state.blocks, refresh = !! ownProps.refresh;

const newBlocks = ownProps.blocks.map( ( block ) => {
block.focused = ownProps.isBlockSelected( block.clientId );
return block;
} );

if ( ! isEqual( blocks, newBlocks ) ) {
blocks = newBlocks;
refresh = ! ownProps.refresh;
}

return {
blocks,
refresh,
};
};

const mapDispatchToProps = ( dispatch, ownProps ) => {
Expand Down
3 changes: 2 additions & 1 deletion src/block-management/block-manager.js
Expand Up @@ -26,7 +26,7 @@ export type BlockListType = {
createBlockAction: ( string, BlockType, string ) => mixed,
parseBlocksAction: string => mixed,
serializeToNativeAction: void => void,
mergeBlocksAction: ( string, string, BlockType ) => mixed,
mergeBlocksAction: ( string, string ) => mixed,
blocks: Array<BlockType>,
aztechtml: string,
refresh: boolean,
Expand All @@ -38,6 +38,7 @@ type StateType = {
showHtml: boolean,
inspectBlocks: boolean,
blockTypePickerVisible: boolean,
blocks: Array<BlockType>,
selectedBlockType: string,
};

Expand Down

0 comments on commit 1a2b13c

Please sign in to comment.