-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
161 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,7 +87,7 @@ class Notification extends Component { | |
} | ||
} | ||
|
||
Notification.newInstance = function newNotificationInstance(properties) { | ||
Notification.newInstance = function newNotificationInstance(properties, callback) { | ||
const { getContainer, ...props } = properties || {}; | ||
let div; | ||
if (getContainer) { | ||
|
@@ -96,22 +96,29 @@ Notification.newInstance = function newNotificationInstance(properties) { | |
div = document.createElement('div'); | ||
document.body.appendChild(div); | ||
} | ||
const notification = ReactDOM.render(<Notification {...props} />, div); | ||
return { | ||
notice(noticeProps) { | ||
notification.add(noticeProps); | ||
}, | ||
removeNotice(key) { | ||
notification.remove(key); | ||
}, | ||
component: notification, | ||
destroy() { | ||
ReactDOM.unmountComponentAtNode(div); | ||
if (!getContainer) { | ||
document.body.removeChild(div); | ||
} | ||
}, | ||
}; | ||
let called = false; | ||
function ref(notification) { | ||
if (called) { | ||
return; | ||
} | ||
called = true; | ||
callback({ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
yesmeck
Member
|
||
notice(noticeProps) { | ||
notification.add(noticeProps); | ||
}, | ||
removeNotice(key) { | ||
notification.remove(key); | ||
}, | ||
component: notification, | ||
destroy() { | ||
ReactDOM.unmountComponentAtNode(div); | ||
if (!getContainer) { | ||
document.body.removeChild(div); | ||
} | ||
}, | ||
}); | ||
} | ||
ReactDOM.render(<Notification {...props} ref={ref} />, div); | ||
}; | ||
|
||
export default Notification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@benjycui 是不是要判断下 callback 是否存在?