Skip to content

Commit ec0d6ac

Browse files
chore: add wrapper communication to readme
1 parent c51676f commit ec0d6ac

1 file changed

Lines changed: 82 additions & 1 deletion

File tree

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,85 @@ docker run \
2727

2828
```docker build -f Dockerfile.prod -t nmrium-rw:prod -m 8g .```
2929

30-
```docker run -it --rm -p 1337:80 nmrium-rw:prod```
30+
```docker run -it --rm -p 1337:80 nmrium-rw:prod```
31+
32+
### Wrapper Events
33+
34+
NMRium wrapper uses a custom event to handle the communication between NMRium and the parent application, for that we create multiple events:
35+
36+
#### Events in action
37+
you can use the events helper functions or create message events manually.
38+
39+
1. Helper function
40+
41+
```ts
42+
import events from '../events';
43+
44+
events.trigger(eventName, data);
45+
46+
events.on(eventName, listenerHandler);
47+
48+
```
49+
50+
2. Message event
51+
52+
```ts
53+
window.postMessage({ type: `nmr-wrapper:${eventName}`, data }, '*');
54+
55+
window.addEventListener(`message`, listenerHandler)
56+
```
57+
58+
#### Events
59+
60+
| name | data/handler | description |
61+
|:---- |------------------- | :---- |
62+
| loadURLs | { urls: [] } | load spectra from external URL |
63+
| load | NMRiumData | load nmrium data |
64+
| error | (error:Error)=>ErrorHanlder | triggered once error happen at level of the wrapper |
65+
| dataChange | (data:NMRiumData)=>{} | triggered when changes happen on the side of NMRIum |
66+
67+
#### Load spectra and molfile from external URLs example:
68+
```ts
69+
import events from '../events';
70+
71+
events.trigger('loadURLs', {
72+
urls: [
73+
'https://cheminfo.github.io/nmr-dataset-demo/cytisine/13c.jdx',
74+
'https://cheminfo.github.io/nmr-dataset-demo/cytisine/1h.jdx',
75+
'https://cheminfo.github.io/bruker-data-test/data/zipped/aspirin-1h.zip',
76+
],
77+
});
78+
```
79+
80+
#### Load NMRium data example:
81+
82+
You can pass NMRium data that you get when you export the data from the NMRium or what you received from dataChange event
83+
```ts
84+
events.trigger('load', {
85+
spectra:[
86+
source:{
87+
jcampURL:""
88+
}
89+
]
90+
});
91+
```
92+
93+
#### Error handler example:
94+
95+
```ts
96+
events.on('error', (error)=>{
97+
// you code here
98+
});
99+
```
100+
101+
#### Data change hander example:
102+
103+
```ts
104+
events.on('dataChange', (data)=>{
105+
// you code here
106+
});
107+
```
108+
109+
110+
111+

0 commit comments

Comments
 (0)