Skip to content

Commit

Permalink
Interactivity API: remove the wp-show directive (#53240)
Browse files Browse the repository at this point in the history
* Remove wp-show

* Remove wp-show e2e tests

* Replace wp-show with wp-fakeshow in the rest of the e2e tests

* Update changelog

* Update changelog with PR number

* Change fakeshow with show-mock
  • Loading branch information
luisherranz authored Aug 2, 2023
1 parent a6d6b9c commit 5bf6aa0
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

?>
<div data-wp-interactive>
<div data-wp-fakeshow="state.isOpen">
<div data-wp-show-mock="state.isOpen">
<input
data-testid="input"
data-wp-effect="effects.elementAddedToTheDOM"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
( ( { wp } ) => {
const { store, directive, useContext, useMemo } = wp.interactivity;
const { store, directive } = wp.interactivity;

// Fake `data-wp-fakeshow` directive to test when things are removed from the DOM.
// Replace with `data-wp-show` when it's ready.
// Fake `data-wp-show-mock` directive to test when things are removed from the
// DOM. Replace with `data-wp-show` when it's ready.
directive(
'fakeshow',
'show-mock',
( {
directives: {
fakeshow: { default: fakeshow },
"show-mock": { default: showMock },
},
element,
evaluate,
context,
} ) => {
const contextValue = useContext( context );
const children = useMemo(
() =>
element.type === 'template'
? element.props.templateChildren
: element,
[]
);
if ( ! evaluate( fakeshow, { context: contextValue } ) ) return null;
return children;
if ( ! evaluate( showMock ) ) return null;
return element;
}
);

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

?>
<div>
<div data-wp-show="state.falseValue">
<div data-wp-show-mock="state.falseValue">
<span data-testid="not inside an island">
This should be shown because it is inside an island.
</span>
</div>

<div data-wp-interactive>
<div data-wp-show="state.falseValue">
<div data-wp-show-mock="state.falseValue">
<span data-testid="inside an island">
This should not be shown because it is inside an island.
</span>
Expand All @@ -23,7 +23,7 @@

<div data-wp-interactive>
<div data-wp-ignore>
<div data-wp-show="state.falseValue">
<div data-wp-show-mock="state.falseValue">
<span
data-testid="inside an inner block of an isolated island"
>
Expand All @@ -37,7 +37,7 @@
<div data-wp-interactive>
<div data-wp-interactive>
<div
data-wp-show="state.falseValue"
data-wp-show-mock="state.falseValue"
data-testid="island inside another island"
>
<span>
Expand All @@ -51,7 +51,7 @@
<div data-wp-interactive>
<div>
<div data-wp-interactive data-wp-ignore>
<div data-wp-show="state.falseValue">
<div data-wp-show-mock="state.falseValue">
<span
data-testid="island inside inner block of isolated island"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
( ( { wp } ) => {
const { store } = wp.interactivity;
const { store, directive, createElement } = wp.interactivity;

// Fake `data-wp-show-mock` directive to test when things are removed from the
// DOM. Replace with `data-wp-show` when it's ready.
directive(
'show-mock',
( {
directives: {
"show-mock": { default: showMock },
},
element,
evaluate,
} ) => {
if ( ! evaluate( showMock ) )
element.props.children =
createElement( "template", null, element.props.children );
}
);

store( {
state: {
Expand Down
4 changes: 4 additions & 0 deletions packages/interactivity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking Change

- Remove the `wp-show` directive until we figure out its final implementation. ([#53240](https://github.com/WordPress/gutenberg/pull/53240))

## 1.2.0 (2023-07-20)

### New Features
Expand Down
20 changes: 0 additions & 20 deletions packages/interactivity/src/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,6 @@ export default () => {
}
);

// data-wp-show
directive(
'show',
( {
directives: {
show: { default: show },
},
element,
evaluate,
context,
} ) => {
const contextValue = useContext( context );

if ( ! evaluate( show, { context: contextValue } ) )
element.props.children = (
<template>{ element.props.children }</template>
);
}
);

// data-wp-ignore
directive(
'ignore',
Expand Down
59 changes: 0 additions & 59 deletions test/e2e/specs/interactivity/directives-show.spec.ts

This file was deleted.

0 comments on commit 5bf6aa0

Please sign in to comment.