libs/core: implement substate() in uci model for creating bound state cursors
This commit is contained in:
parent
28b5b2b637
commit
21de97b235
1 changed files with 26 additions and 0 deletions
|
@ -227,6 +227,32 @@ function Cursor._affected(self, configlist)
|
||||||
return reloadlist
|
return reloadlist
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Create a sub-state of this cursor. The sub-state is tied to the parent
|
||||||
|
-- curser, means it the parent unloads or loads configs, the sub state will
|
||||||
|
-- do so as well.
|
||||||
|
-- @return UCI state cursor tied to the parent cursor
|
||||||
|
function Cursor.substate(self)
|
||||||
|
Cursor._substates = Cursor._substates or { }
|
||||||
|
Cursor._substates[self] = Cursor._substates[self] or cursor_state()
|
||||||
|
return Cursor._substates[self]
|
||||||
|
end
|
||||||
|
|
||||||
|
local _load = Cursor.load
|
||||||
|
function Cursor.load(self, ...)
|
||||||
|
if Cursor._substates and Cursor._substates[self] then
|
||||||
|
_load(Cursor._substates[self], ...)
|
||||||
|
end
|
||||||
|
return _load(self, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
local _unload = Cursor.unload
|
||||||
|
function Cursor.unload(self, ...)
|
||||||
|
if Cursor._substates and Cursor._substates[self] then
|
||||||
|
_unload(Cursor._substates[self], ...)
|
||||||
|
end
|
||||||
|
return _unload(self, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Add an anonymous section.
|
--- Add an anonymous section.
|
||||||
-- @class function
|
-- @class function
|
||||||
|
|
Loading…
Reference in a new issue