Skip to content

Commit

Permalink
Fix setting up middlewares when creating gutenberg stores
Browse files Browse the repository at this point in the history
  • Loading branch information
Tug committed Feb 6, 2019
1 parent d020ce7 commit 940d337
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @flow
* @format */

import { AppRegistry } from 'react-native';
import App from './src/app/App';
AppRegistry.registerComponent( 'gutenberg', () => App );
import { setupApp } from './src';

setupApp();
19 changes: 0 additions & 19 deletions src/app/App.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
/** @flow
* @format */

import '../globals';

import React from 'react';

// Gutenberg imports
import { registerCoreBlocks } from '@wordpress/block-library';
import { registerBlockType, setUnregisteredTypeHandlerName, unregisterBlockType } from '@wordpress/blocks';

import AppContainer from './AppContainer';
import initialHtml from './initial-html';

import * as UnsupportedBlock from '../block-types/unsupported-block/';

registerCoreBlocks();
registerBlockType( UnsupportedBlock.name, UnsupportedBlock.settings );
setUnregisteredTypeHandlerName( UnsupportedBlock.name );

// disable Code and More blocks for release
if ( ! __DEV__ ) {
unregisterBlockType( 'core/code' );
unregisterBlockType( 'core/more' );
}

type PropsType = {
initialData: string,
initialHtmlModeEnabled: boolean,
Expand Down
3 changes: 3 additions & 0 deletions src/app/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import renderer from 'react-test-renderer';

import { setupApp } from '..';
import App from './App';
import BlockHolder from '../block-management/block-holder';
import { dispatch, select } from '@wordpress/data';

describe( 'App', () => {
beforeAll( setupApp );

it( 'renders without crashing', () => {
const app = renderer.create( <App /> );
const rendered = app.toJSON();
Expand Down
48 changes: 48 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// External dependencies
import { AppRegistry } from 'react-native';

// Setting up environment
import './globals';

const gutenbergSetup = () => {
const apiFetch = require( '@wordpress/api-fetch' ).default;
const wpData = require( '@wordpress/data' );

// wp-api-fetch
apiFetch.use( apiFetch.createRootURLMiddleware( 'https://public-api.wordpress.com/' ) );

// wp-data
const userId = 1;
const storageKey = 'WP_DATA_USER_' + userId;
wpData.use( wpData.plugins.persistence, { storageKey: storageKey } );
wpData.use( wpData.plugins.controls );
};

const editorSetup = () => {
const wpBlockLibrary = require( '@wordpress/block-library' );
const wpBlocks = require( '@wordpress/blocks' );
const registerCoreBlocks = wpBlockLibrary.registerCoreBlocks;
const registerBlockType = wpBlocks.registerBlockType;
const setUnregisteredTypeHandlerName = wpBlocks.setUnregisteredTypeHandlerName;
const unregisterBlockType = wpBlocks.unregisterBlockType;
const UnsupportedBlock = require( './block-types/unsupported-block' );

// register and setup blocks
registerCoreBlocks();
registerBlockType( UnsupportedBlock.name, UnsupportedBlock.settings );
setUnregisteredTypeHandlerName( UnsupportedBlock.name );

// disable Code and More blocks for release
if ( ! __DEV__ ) {
unregisterBlockType( 'core/code' );
unregisterBlockType( 'core/more' );
}
};

export function setupApp() {
gutenbergSetup();
editorSetup();

// Making sure the environment is set up before loading any Component
AppRegistry.registerComponent( 'gutenberg', () => require( './app/App' ).default );
}

0 comments on commit 940d337

Please sign in to comment.