mirror of
https://github.com/wassname/talk.git
synced 2026-07-09 21:18:58 +08:00
unregister hooks
This commit is contained in:
@@ -101,7 +101,7 @@ class CommentBox extends Component {
|
||||
this.setState({body: ''});
|
||||
}
|
||||
|
||||
addCommentHooks = (hooks = {}) => {
|
||||
registerHook = (hooks = {}) => {
|
||||
if (typeof hooks === 'object') {
|
||||
this.setState(() => ({
|
||||
hooks: merge(this.state.hooks, hooks)
|
||||
@@ -110,6 +110,22 @@ class CommentBox extends Component {
|
||||
return this.state.hooks;
|
||||
}
|
||||
|
||||
unregisterHook = (hookType = '', hook = '') => {
|
||||
const hooks = this.state.hooks;
|
||||
|
||||
if (hooks[hookType]) {
|
||||
if (hooks[hookType][hook]) {
|
||||
delete hooks[hookType][hook];
|
||||
} else {
|
||||
console.warn(`${hook} is invalid. Cannot unregister ${hook} Hook `);
|
||||
}
|
||||
} else {
|
||||
console.warn(`${hookType} does not exist. Cannot unregister ${hook} Hook `);
|
||||
}
|
||||
|
||||
this.setState(() => ({hooks}));
|
||||
}
|
||||
|
||||
render () {
|
||||
const {styles, isReply, authorId, charCount} = this.props;
|
||||
let {cancelButtonClicked} = this.props;
|
||||
@@ -148,7 +164,8 @@ class CommentBox extends Component {
|
||||
|
||||
<Slot
|
||||
fill="commentBoxDetail"
|
||||
addCommentHooks={this.addCommentHooks}
|
||||
registerHook={this.registerHook}
|
||||
unregisterHook={this.unregisterHook}
|
||||
inline
|
||||
/>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class OffTopicCheckbox extends React.Component {
|
||||
|
||||
handleChange = (e) => {
|
||||
if (e.target.checked) {
|
||||
this.props.addCommentHooks({
|
||||
this.props.registerHook({
|
||||
postSubmit: {
|
||||
addTag: (data) => {
|
||||
const {comment} = data.createComment;
|
||||
@@ -19,11 +19,7 @@ class OffTopicCheckbox extends React.Component {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.props.addCommentHooks({
|
||||
postSubmit: {
|
||||
addTag: () => {}
|
||||
}
|
||||
})
|
||||
this.props.unregisterHook('postSubmit', 'addTag');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user