Repository navigation
Expand file tree
/
Copy pathnote_editor_agent.h
More file actions
51 lines (42 loc) · 2.07 KB
/
Copy pathnote_editor_agent.h
File metadata and controls
51 lines (42 loc) · 2.07 KB
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
// Generated by Ordo State Designer -- regenerated wholesale on every
// [Generate C++] click. DO NOT EDIT -- your changes will be overwritten on
// the next generation. NoteEditorStateAgent -- the kernel face of NoteEditorCore.
// Implement hooks in the domain/ stubs next to these files: the generator
// writes them once and never overwrites them.
#pragma once
#include <ordo/core/agent.h>
#include "note_editor_core.h"
#include "note_editor_events.h"
#include "note_editor_hooks.h"
#include "note_editor_state.h"
namespace app::generated::note_editor {
// Mutate-then-publish, the ordo Agent role: the agent OWNS a NoteEditorCore
// and wires its state-change callback to ONE events::StateChanged fact
// per committed transition -- the "changed" broadcast. No firing logic
// lives here; the core is the only place it is emitted. Multiple
// machines/kernels may register an instance of this class each under
// kName -- unique per machine, not per kernel.
//
// The injected hooks reach the core through this constructor, so they
// must outlive the agent -- note_editor_bootstrap.h's registerNoteEditor() std::ref-
// injects them.
class NoteEditorStateAgent : public ordo::core::Agent {
public:
static constexpr const char* kName = "note_editor_state";
NoteEditorStateAgent(NoteEditorGuards& guards, NoteEditorActions& actions)
: Agent(kName), core_(guards, actions) {
core_.setOnStateChanged([this](NoteEditorState previous, NoteEditorState next) {
send(events::StateChanged{previous, next});
});
}
// No single state() accessor here -- see NoteEditorCore's own header
// comment for why (a Parallel configuration has no one value).
bool isActive(NoteEditorState state) const { return core_.isActive(state); }
// The kernel-free face: note_editor_commands.h fires events through this,
// and any non-kernel owner can drive the same core directly.
NoteEditorCore& core() { return core_; }
const NoteEditorCore& core() const { return core_; }
private:
NoteEditorCore core_;
};
} // namespace app::generated::note_editor