Skip to content

3. Wrapper Events

Chandu Nainala edited this page Mar 23, 2023 · 1 revision

NMRium wrapper uses a custom event to handle the communication between NMRium and the parent application, for that we create MessageEvents by using a window interface. We provide two events helper functions in /src/events/event.ts, which you can use by importing events.

import events from '../events';

events.trigger(eventName, data);

events.on(eventName, listenerHandler);

Events

name data/handler description
load LoadData Object load spectra and molecules
error (error:Error)=>ErrorHanlder triggered once error happen at level of the wrapper
dataChange (data:NMRiumData)=>{} triggered when changes happen on the side of NMRium
actionRequest ActionRequest Object export spectra viewer as blob
actionResponse ActionResponse Object export spectra viewer as blob

Load spectra and molfile files:

 import events from '../events';

events.trigger('load', {
			  data: [File1,File2,....etc],
			  type:"file"
			}
	       );

Load spectra and molfile from external URLs example:

 import events from '../events';

events.trigger('load', {
			  data: [
			    'https://cheminfo.github.io/nmr-dataset-demo/cytisine/13c.jdx',
			    'https://cheminfo.github.io/bruker-data-test/data/zipped/aspirin-1h.zip',
			    ...etc
			  ],
			  type:"url"
			}
	       );

Load NMRium data example:

You can pass NMRium data that you get when you export the data from the NMRium or what you received from dataChange event

events.trigger('load', { 
                         data: {
				  spectra:[
				       source:{
					     jcampURL:""
					 }
				     ]
				},
		         type:"nmrium"
		       }
                  );

Error handler example:

events.on('error', (error)=>{
// you code here
});

Data change hander example:

events.on('dataChange', (data)=>{
// you code here
});