@@ -4,6 +4,7 @@ import NMRium, { NMRiumData } from 'nmrium';
44import Button from 'nmrium/lib/component/elements/Button' ;
55import { useEffect , useState } from 'react' ;
66import events from './events' ;
7+ import observableEvents from './observables' ;
78import useActions from './hooks/useActions' ;
89
910const styles = {
@@ -16,6 +17,7 @@ const styles = {
1617 height : 40px ;
1718 width : 100% ;
1819 padding : 5px ;
20+ display : flex;
1921 ` ,
2022 wrapper : css `
2123 flex : 1 ;
@@ -40,20 +42,41 @@ export default function NMRiumWrapper() {
4042 const actionHandler = useActions ( ) ;
4143
4244 useEffect ( ( ) => {
43- events . on ( 'load' , ( _data ) => {
45+ const unsubscribe = observableEvents . subscribe ( 'load' , ( _data ) => {
46+ // eslint-disable-next-line no-console
47+ console . log ( 'test load data with subscribe' ) ;
4448 setDate ( _data ) ;
4549 } ) ;
50+
51+ const clearListener = events . on ( 'load' , ( _data ) => {
52+ // eslint-disable-next-line no-console
53+ console . log ( 'test load data with custom event' ) ;
54+ setDate ( _data ) ;
55+ } ) ;
56+
57+ return ( ) => {
58+ clearListener ( ) ;
59+ unsubscribe ( ) ;
60+ } ;
4661 } ) ;
4762
4863 return (
4964 < div css = { styles . container } >
5065 < div css = { styles . header } >
5166 < Button . Done
67+ style = { { margin : '0 10px' } }
5268 onClick = { ( ) => {
5369 events . trigger ( 'load' , testData ) ;
5470 } }
5571 >
56- Test Load from external URL
72+ Trigger load custom event
73+ </ Button . Done >
74+ < Button . Done
75+ onClick = { ( ) => {
76+ observableEvents . trigger ( 'load' , testData ) ;
77+ } }
78+ >
79+ Test Load observable
5780 </ Button . Done >
5881 </ div >
5982
0 commit comments