-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.hpp
More file actions
32 lines (26 loc) · 796 Bytes
/
App.hpp
File metadata and controls
32 lines (26 loc) · 796 Bytes
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
#pragma once
#include <asm-dom.hpp>
// Essentially global app state and controller
class App {
public:
void pageRender(asmdom::VNode* newVnode) {
static auto vdomReplaced = false;
if (!vdomReplaced) {
const auto root =
emscripten::val::global("document").call<emscripten::val>("getElementById", std::string("root"));
_currentVnode = asmdom::patch(root, newVnode);
vdomReplaced = true;
} else {
_currentVnode = asmdom::patch(_currentVnode, newVnode);
}
}
// application state -- shared state needed by multiple page views
double cartValue{};
private:
// asmdom state
asmdom::VNode* _currentVnode = nullptr;
};
inline App& getApp() {
static App a;
return a;
}