Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Add wp-log directive to test this
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Sep 22, 2022
1 parent d04ee91 commit 9057066
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/blocks/interactive-parent/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ const View = ({
fontWeight: bold ? 900 : fontWeight,
}}
>
<h2 className="title">{title}</h2>
<h2
data-wp-block-log="the header of interactive-parent was rendered"
className="title"
>
{title}
</h2>
<button onClick={() => setShow(!show)}>Show</button>
<button onClick={() => setBold(!bold)}>Bold</button>
<button onClick={() => setCounter(counter + 1)}>
Expand Down
7 changes: 6 additions & 1 deletion src/blocks/non-interactive-parent/view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const View = ({ attributes, blockProps, children }) => (
<div {...blockProps}>
<h4 className="title">{attributes.title}</h4>
<h4
data-wp-block-log="the header of non-interactive-parent was rendered"
className="title"
>
{attributes.title}
</h4>
{children}
</div>
);
Expand Down
8 changes: 8 additions & 0 deletions src/directives/wp-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useEffect } from 'preact/hooks';
import { directive } from '../gutenberg-packages/directives';

directive('log', ({ wpBlock: { log } }) => {
useEffect(() => {
console.log(log);
}, [log]);
});
1 change: 1 addition & 0 deletions src/gutenberg-packages/hydration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { hydrate } from 'preact/compat';
import toVdom from './to-vdom';
import '../directives/wp-block';
import '../directives/wp-block-context';
import '../directives/wp-log';

const dom = document.querySelector('.wp-site-blocks');
const vdom = toVdom(dom).props.children;
Expand Down

0 comments on commit 9057066

Please sign in to comment.