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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/*
* SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
import { configure } from 'mobx';
import { type Root, createRoot } from 'react-dom/client';
import App from './App';
import RootStore from './RootStore';
const initialValue = `// Metamodel
class Person {
contains Post[] posts opposite author
Person[] friend opposite friend
}
class Post {
container Person author opposite posts
Post replyTo
}
// Constraints
error replyToNotFriend(Post x, Post y) <->
replyTo(x, y),
author(x, xAuthor),
author(y, yAuthor),
xAuthor != yAuthor,
!friend(xAuthor, yAuthor).
error replyToCycle(Post x) <-> replyTo+(x, x).
// Instance model
friend(a, b).
author(p1, a).
author(p2, b).
!author(Post::new, a).
// Scope
scope Post = 10..15, Person += 0.
`;
configure({
enforceActions: 'always',
});
let HotRootStore = RootStore;
let HotApp = App;
function createStore(): RootStore {
return new HotRootStore(initialValue);
}
let rootStore = createStore();
let root: Root | undefined;
function render(): void {
root?.render(<HotApp rootStore={rootStore} />);
}
if (import.meta.hot) {
import.meta.hot.accept('./App', (module) => {
if (module === undefined) {
return;
}
({ default: HotApp } = module as unknown as typeof import('./App'));
render();
});
import.meta.hot.accept('./RootStore', (module) => {
if (module === undefined) {
return;
}
({ default: HotRootStore } =
module as unknown as typeof import('./RootStore'));
rootStore.dispose();
rootStore = createStore();
render();
});
}
document.addEventListener('DOMContentLoaded', () => {
const rootElement = document.getElementById('app');
if (rootElement !== null) {
root = createRoot(rootElement);
render();
}
});
|