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)
-- store binding
local with = value.wfunc;
local set = value.store[value.key];
if set then
local tstore = value.store;
local rawKey = value.key;
local set = store[rawKey];
if set or (rawKey:match(",") and with) then
if with then
set = with(set);
set = with(item,tstore,set,value.key);
end
setProperty(item,index,set,ClassName);
else
@ -113,12 +115,12 @@ function module.init(shared)
local from = value.fvalue;
-- adding event function
local function regFn(newValue,store)
local function regFn(_,newValue,key)
if from then
newValue = from[newValue];
end
if with then
newValue = with(newValue,item,store);
newValue = with(item,tstore,newValue,key);
end
if tween then
if not advancedTween then

View file

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