Skip to content

Commit 8d0fb8e

Browse files
refactor(demo): explicitly initialize nmrium core
1 parent 70f737f commit 8d0fb8e

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/demo/views/AuoProcessingView.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import type { NMRiumCore } from '@zakodium/nmrium-core';
1+
import init from '@zakodium/nmrium-core-plugins';
22
import { FileCollection } from 'file-collection';
33
import { useEffect, useState } from 'react';
44

5-
import { useCore } from '../../component/context/CoreContext.js';
6-
75
import type { BaseViewProps } from './BaseView.js';
86
import BaseView from './BaseView.js';
97
import { Loading } from './Loading.js';
108

9+
const core = init();
10+
1111
interface ExternalLoadViewProps extends Omit<BaseViewProps, 'data'> {
1212
file: string;
1313
baseURL: string;
1414
}
1515

16-
async function loadSpectrumFromURL(core: NMRiumCore, url: string) {
16+
async function loadSpectrumFromURL(url: string) {
1717
const { pathname: relativePath, origin: baseURL } = new URL(url);
1818
const source = {
1919
entries: [
@@ -34,15 +34,14 @@ async function loadSpectrumFromURL(core: NMRiumCore, url: string) {
3434

3535
export default function ExternalLoadView(props: ExternalLoadViewProps) {
3636
const [data, setData] = useState();
37-
const core = useCore();
3837

3938
const { file, baseURL, ...otherProps } = props;
4039

4140
useEffect(() => {
42-
void loadSpectrumFromURL(core, file).then((d: any) => {
41+
void loadSpectrumFromURL(file).then((d: any) => {
4342
setData(d);
4443
});
45-
}, [baseURL, core, file]);
44+
}, [baseURL, file]);
4645

4746
if (!data) {
4847
return <Loading />;

src/demo/views/WebSourceView.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import type { CustomWorkspaces, NMRiumCore } from '@zakodium/nmrium-core';
1+
import type { CustomWorkspaces } from '@zakodium/nmrium-core';
2+
import init from '@zakodium/nmrium-core-plugins';
23
import { useCallback, useEffect, useState } from 'react';
34
import { ObjectInspector } from 'react-inspector';
45

5-
import { useCore } from '../../component/context/CoreContext.js';
66
import type { NMRiumWorkspace } from '../../component/main/index.js';
77
import { NMRium } from '../../component/main/index.js';
88
import type { PageConfig } from '../layouts/Main.js';
99

10-
async function loadFromURL(core: NMRiumCore, url: string) {
10+
const core = init();
11+
12+
async function loadFromURL(url: string) {
1113
const { pathname: relativePath, origin: baseURL } = new URL(url);
1214
return core.readFromWebSource({ entries: [{ relativePath, baseURL }] });
1315
}
@@ -36,12 +38,11 @@ export default function WebSourceView(props: WebSourceViewProps) {
3638
const [callbackData, setCallbackData] = useState<any[]>([]);
3739
const [isCallbackVisible, showCallback] = useState(false);
3840

39-
const core = useCore();
4041
useEffect(() => {
41-
void loadFromURL(core, file).then((d) => {
42+
void loadFromURL(file).then((d) => {
4243
setData(d as any);
4344
});
44-
}, [baseURL, core, file, props]);
45+
}, [baseURL, file, props]);
4546

4647
const changeHandler = useCallback((logData) => {
4748
setCallbackData((prevLogs) => {

0 commit comments

Comments
 (0)