Skip to content

Commit

Permalink
Simplify the proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Aug 19, 2022
1 parent 6fd9d52 commit c107cd0
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 94 deletions.
20 changes: 0 additions & 20 deletions packages/block-library/src/experiments.js

This file was deleted.

12 changes: 10 additions & 2 deletions packages/block-library/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ import {
setUnregisteredTypeHandlerName,
setGroupingBlockName,
} from '@wordpress/blocks';
import {
registerAccessToken,
registerExperimentalAPIs
} from '@wordpress/experiments';

const ACCESS_TOKEN = {
i_realize_my_code_will_break_in_a_few_months_once_the_experimental_apis_are_removed: true,
};
registerAccessToken( ACCESS_TOKEN, '@wordpress/block-library' );

/**
* Internal dependencies
*/
import { registerExperimentalAPIs } from './experiments';
// When IS_GUTENBERG_PLUGIN is set to false, imports of experimental blocks
// are transformed by packages/block-library/src/index.js as follows:
// import * as experimentalBlock from './experimental-block'
Expand Down Expand Up @@ -308,7 +316,7 @@ export const __experimentalRegisterExperimentalCoreBlocks = process.env
}
: undefined;

registerExperimentalAPIs( {
registerExperimentalAPIs( ACCESS_TOKEN, {
__experimentalGetCoreBlocks,
__experimentalRegisterExperimentalCoreBlocks,
} );
23 changes: 0 additions & 23 deletions packages/blocks/src/experiments.js

This file was deleted.

21 changes: 15 additions & 6 deletions packages/blocks/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@
// Blocks are inferred from the HTML source of a post through a parsing mechanism
// and then stored as objects in state, from which it is then rendered for editing.

/**
* Internal dependencies
*/
import { registerExperimentalAPIs, getExperimentalAPIs } from './experiments';
/**
* WordPress dependencies
*/
import {
registerAccessToken,
registerExperimentalAPIs,
getExperimentalAPIs
} from '@wordpress/experiments';

const ACCESS_TOKEN = {
i_realize_my_code_will_break_in_a_few_months_once_the_experimental_apis_are_removed: true,
};
registerAccessToken( ACCESS_TOKEN, '@wordpress/blocks' );

import { store } from './store';
export { store };
export * from './api';
Expand All @@ -27,10 +34,12 @@ import {
} from './api';

const { __experimentalPrivateDispatch } =
getExperimentalAPIs( '@wordpress/data' );
registerExperimentalAPIs( {
getExperimentalAPIs( ACCESS_TOKEN, '@wordpress/data' );

registerExperimentalAPIs( ACCESS_TOKEN, {
__unstableGetInnerBlocksProps,
unstable__bootstrapServerSideBlockDefinitions,

__experimentalReapplyBlockTypeFilters: () => {
__experimentalPrivateDispatch(
store,
Expand Down
20 changes: 0 additions & 20 deletions packages/core-data/src/experiments.js

This file was deleted.

14 changes: 13 additions & 1 deletion packages/core-data/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
* WordPress dependencies
*/
import { createReduxStore, register } from '@wordpress/data';
import {
registerAccessToken,
registerExperimentalAPIs,
} from '@wordpress/experiments';

const ACCESS_TOKEN = {
i_realize_my_code_will_break_in_a_few_months_once_the_experimental_apis_are_removed: true,
};
registerAccessToken( ACCESS_TOKEN, '@wordpress/core-data' );

/**
* Internal dependencies
*/
import './experiments';
import reducer from './reducer';
import * as selectors from './selectors';
import * as actions from './actions';
Expand Down Expand Up @@ -78,3 +86,7 @@ export * from './entity-types';
export * from './fetch';
export * from './hooks';

import { __experimentalFetchLinkSuggestions } from "./fetch";
registerExperimentalAPIs( ACCESS_TOKEN, {
__experimentalFetchLinkSuggestions,
} );
17 changes: 0 additions & 17 deletions packages/data/src/experiments.js

This file was deleted.

16 changes: 14 additions & 2 deletions packages/data/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@
*/
import combineReducers from 'turbo-combine-reducers';

/**
* WordPress dependencies
*/
import {
registerAccessToken,
registerExperimentalAPIs
} from '@wordpress/experiments';

const ACCESS_TOKEN = {
i_realize_my_code_will_break_in_a_few_months_once_the_experimental_apis_are_removed: true,
};
registerAccessToken( ACCESS_TOKEN, '@wordpress/data' );

/**
* Internal dependencies
*/
import { registerExperimentalAPIs } from './experiments';
import defaultRegistry from './default-registry';
import * as plugins from './plugins';

Expand Down Expand Up @@ -237,7 +249,7 @@ function __experimentalPrivateDispatch( { name }, actionThunk ) {
return defaultRegistry.stores[ name ].store.dispatch( actionThunk );
}

registerExperimentalAPIs( {
registerExperimentalAPIs( ACCESS_TOKEN, {
__experimentalPrivateSelector,
__experimentalPrivateDispatch,
} );
6 changes: 3 additions & 3 deletions packages/experiments/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const CORE_MODULES_USING_EXPERIMENTS = [
const accessTokens = [];
const registeredExperiments = {};

export function registerAccessToken( accessToken, packageName ) {
export const registerAccessToken = ( accessToken, packageName ) => {
if ( ! CORE_MODULES_USING_EXPERIMENTS.includes( packageName ) ) {
throw new Error(
`Cannot register non-gutenberg package ${ packageName }.`
Expand All @@ -32,7 +32,7 @@ export function registerAccessToken( accessToken, packageName ) {
registeredExperiments[ packageName ] = { experiments: {}, accessToken };
}

export function registerExperimentalAPIs( accessToken, experiments ) {
export const registerExperimentalAPIs = ( accessToken, experiments ) => {
const registeredEntry = Object.entries( registeredExperiments ).find(
( [ , details ] ) => details.accessToken === accessToken
);
Expand All @@ -46,7 +46,7 @@ export function registerExperimentalAPIs( accessToken, experiments ) {
};
}

export function getExperimentalAPIs( accessToken, packageName ) {
export const getExperimentalAPIs = ( accessToken, packageName ) => {
if ( ! ( packageName in registeredExperiments ) ) {
throw new Error( `Module ${ packageName } is not registered yet.` );
}
Expand Down

0 comments on commit c107cd0

Please sign in to comment.