Skip to content

Commit

Permalink
Fix <Prompt> when message changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Dec 31, 2016
1 parent 03dac3c commit 15dc4eb
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions modules/Prompt.js
Expand Up @@ -20,33 +20,36 @@ class Prompt extends React.Component {
when: true
}

block() {
if (!this.teardownPrompt)
this.teardownPrompt = this.context.history.block(this.props.message)
enable(message) {
if (this.unblock)
this.unblock()

this.unblock = this.context.history.block(message)
}

unblock() {
if (this.teardownPrompt) {
this.teardownPrompt()
this.teardownPrompt = null
disable() {
if (this.unblock) {
this.unblock()
this.unblock = null
}
}

componentWillMount() {
if (this.props.when)
this.block()
this.enable(this.props.message)
}

componentWillReceiveProps(nextProps) {
if (nextProps.when) {
this.block()
if (!this.props.when || this.props.message !== nextProps.message)
this.enable(nextProps.message)
} else {
this.unblock()
this.disable()
}
}

componentWillUnmount() {
this.unblock()
this.disable()
}

render() {
Expand Down

0 comments on commit 15dc4eb

Please sign in to comment.