forked from bhouston/behave-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
useRegistry.ts
35 lines (29 loc) · 944 Bytes
/
useRegistry.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {
DefaultLogger,
ILifecycleEventEmitter,
ILogger,
ManualLifecycleEventEmitter,
registerCoreProfile,
Registry
} from '@behave-graph/core';
import { useEffect, useState } from 'react';
const useRegistry = ({
registerProfiles
}: {
registerProfiles: (registry: Registry) => void;
}) => {
const [registry, setRegistry] = useState<Registry>();
const [lifecyleEmitter, setLifecycleEmitter] =
useState<ILifecycleEventEmitter>(new ManualLifecycleEventEmitter());
const [logger] = useState<ILogger>(new DefaultLogger());
useEffect(() => {
const registry = new Registry();
const lifecyleEmitter = new ManualLifecycleEventEmitter();
registerCoreProfile(registry, logger, lifecyleEmitter);
registerProfiles(registry);
setRegistry(registry);
setLifecycleEmitter(lifecyleEmitter);
}, [registerProfiles, logger]);
return { registry, lifecyleEmitter, logger };
};
export default useRegistry;