-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds unmountComponentAtNode top level api.
- Loading branch information
Revanth Mahesh
committed
Jul 17, 2019
1 parent
dc7383c
commit 1a521b6
Showing
5 changed files
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Brahmos, { Component, unmountComponentAtNode } from '../src'; | ||
|
||
export default class UnMountAtNode extends Component { | ||
|
||
removeNode = () => { | ||
setTimeout(() => { | ||
unmountComponentAtNode( document.getElementById( 'unmount-node' ) ); | ||
}, 1000); | ||
} | ||
componentWillUnmount(){ | ||
console.log( 'component will unmount life cycle called!!' ); | ||
} | ||
render () { | ||
return ( | ||
<div> | ||
<p> Remove a mounted Brahmos component from the DOM and clean up its event handlers and state. If no component was mounted in the container, calling this function does nothing. Returns true if a component was unmounted and false if there was no component to unmount. </p> | ||
<div> | ||
<button onClick={ this.removeNode }> Remove node</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import App from './App.js'; | ||
import UnMountAtNode from './UnMountAtNode'; | ||
import Brahmos, { render } from '../src'; | ||
|
||
render(<App />, document.getElementById('app')); | ||
|
||
render( <UnMountAtNode/>, document.getElementById('unmount-node')) |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import tearDown from './tearDown'; | ||
|
||
function unmountComponentAtNode( container ){ | ||
/** | ||
* if container has a brahmosNode, it will be tear down. | ||
*/ | ||
if( container.__brahmosNode ){ | ||
tearDown( container.__brahmosNode, { parentNode: container } ); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
export default unmountComponentAtNode; |