multi store connection

This commit is contained in:
세젤귀 고양이들 2021-12-24 21:32:25 +09:00
parent 739d441405
commit 7d4655bb65
2 changed files with 19 additions and 10 deletions

View file

@ -97,10 +97,12 @@ function module.init(shared)
if indexType == "string" and valueType == "table" and value.t == "reg" then -- register (bind to store event) if indexType == "string" and valueType == "table" and value.t == "reg" then -- register (bind to store event)
-- store binding -- store binding
local with = value.wfunc; local with = value.wfunc;
local set = value.store[value.key]; local tstore = value.store;
if set then local rawKey = value.key;
local set = store[rawKey];
if set or (rawKey:match(",") and with) then
if with then if with then
set = with(set); set = with(item,tstore,set,value.key);
end end
setProperty(item,index,set,ClassName); setProperty(item,index,set,ClassName);
else else
@ -113,12 +115,12 @@ function module.init(shared)
local from = value.fvalue; local from = value.fvalue;
-- adding event function -- adding event function
local function regFn(newValue,store) local function regFn(_,newValue,key)
if from then if from then
newValue = from[newValue]; newValue = from[newValue];
end end
if with then if with then
newValue = with(newValue,item,store); newValue = with(item,tstore,newValue,key);
end end
if tween then if tween then
if not advancedTween then if not advancedTween then

View file

@ -86,7 +86,17 @@ function module.init(shared)
local registerMt = { local registerMt = {
register = function (s,efunc) register = function (s,efunc)
insert(s.event,efunc); local self = s.store;
local events = self.__evt;
for key in s.key:gmatch("[^,]+") do
key = key:gsub("^ +",""):gsub(" +$","");
local event = events[key];
if not event then
event = setmetatable({},week);
events[key] = event;
end
insert(event,efunc);
end
end; end;
with = function (s,efunc) with = function (s,efunc)
return setmetatable({wfunc = efunc},{__index = s}); return setmetatable({wfunc = efunc},{__index = s});
@ -114,17 +124,14 @@ function module.init(shared)
local event = self.__evt[key]; local event = self.__evt[key];
if event then if event then
for _,v in pairs(event) do -- NO ipairs here for _,v in pairs(event) do -- NO ipairs here
wrap(catch)(v,value,store); wrap(catch)(v,store,value,key);
end end
end end
end end
function store:__call(key,func) function store:__call(key,func)
local register = self.__reg[key]; local register = self.__reg[key];
if not register then if not register then
local event = setmetatable({},week);
self.__evt[key] = event;
register = setmetatable({ register = setmetatable({
event = event;
key = key; key = key;
store = self; store = self;
t = "reg"; t = "reg";