-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
46 lines (38 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* External dependencies
*/
import memize from 'memize';
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
/**
* Internal dependencies
*/
import Edit from './edit';
import { BlockEditContextProvider } from './context';
class BlockEdit extends Component {
constructor() {
super( ...arguments );
// It is important to return the same object if props haven't changed
// to avoid unnecessary rerenders.
// See https://reactjs.org/docs/context.html#caveats.
this.propsToContext = memize(
this.propsToContext.bind( this ),
{ maxSize: 1 }
);
}
propsToContext( name, isSelected, clientId, onFocus, onCaretVerticalPositionChange ) {
return { name, isSelected, clientId, onFocus, onCaretVerticalPositionChange };
}
render() {
const { name, isSelected, clientId, onFocus, onCaretVerticalPositionChange } = this.props;
const value = this.propsToContext( name, isSelected, clientId, onFocus, onCaretVerticalPositionChange );
return (
<BlockEditContextProvider value={ value }>
<Edit { ...this.props } />
</BlockEditContextProvider>
);
}
}
export default BlockEdit;