Skip to content

Packages: Publish all modules as independent npm packages #3955

Closed
@Shelob9

Description

@Shelob9

Issue Overview and Possible Solution

When creating a block, I start with something like this:

const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks; 
const BlockControls = wp.blocks.BlockControls;
const el = wp.element.createElement;

Strong coupling to global state is consistent with traditional WordPress anti-patterns. But it presents the following problems:

  1. Gutenberg might not be active (3k active installs) or the site might not be on WordPress 5.0 yet (currently ~77% of WordPress sites are not on the current release series.)
  2. Relying on global state makes testing very hard and/or impossible depending on test type/ technology.
  3. I may wish to use these components in my plugin or other type of code that isn't strongly-coupled to WordPress and including them via npm and an import statement is how that should work.

Expected Behavior

$ npm i @wordpress/element
import { createElement } from '@wordpress/element';

Current Behavior

const { createElement } = wp.element;

Tasks

Metadata

Metadata

Labels

FrameworkIssues related to broader framework topics, especially as it relates to javascript[Feature] ExtensibilityThe ability to extend blocks or the editing experience[Type] EnhancementA suggestion for improvement.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions