-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlifecycle_coordinator.lua
More file actions
78 lines (66 loc) · 1.74 KB
/
lifecycle_coordinator.lua
File metadata and controls
78 lines (66 loc) · 1.74 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
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
-- Golden Test 2: Boilerplate-Dominated Lifecycle Coordinator
-- This file should be REJECTED by the analyzer (no nucleus, no leverage point)
-- Reason: All logic is lifecycle/setup/wiring code without semantic center
local M = {}
local state = {}
local callbacks = {}
-- Lifecycle: initialization boilerplate
function M.init()
state.initialized = false
state.ready = false
state.loading = true
callbacks = {}
end
-- Lifecycle: registration boilerplate
function M.register_callback(name, fn)
if not callbacks[name] then
callbacks[name] = {}
end
table.insert(callbacks[name], fn)
end
-- Lifecycle: notification boilerplate
local function notify_callbacks(name, ...)
if callbacks[name] then
for _, fn in ipairs(callbacks[name]) do
fn(...)
end
end
end
-- Lifecycle: setup boilerplate
function M.setup()
if state.initialized then
return
end
state.initialized = true
notify_callbacks('setup_complete')
end
-- Lifecycle: teardown boilerplate
function M.teardown()
state.initialized = false
state.ready = false
callbacks = {}
notify_callbacks('teardown_complete')
end
-- Lifecycle: ready check boilerplate
function M.is_ready()
return state.ready and state.initialized
end
-- Lifecycle: state setter boilerplate
function M.set_ready(ready)
state.ready = ready
if ready then
notify_callbacks('ready_changed', true)
else
notify_callbacks('ready_changed', false)
end
end
-- Lifecycle: loading check boilerplate
function M.is_loading()
return state.loading
end
-- Lifecycle: loading setter boilerplate
function M.set_loading(loading)
state.loading = loading
notify_callbacks('loading_changed', loading)
end
return M