This commit is contained in:
세젤귀 고양이들 2021-12-19 16:32:16 +09:00
commit 11bd501a6b
2 changed files with 19 additions and 4 deletions

View file

@ -91,11 +91,22 @@ function module.init(shared)
item[index] = dset;
end
end
value.register(function (newValue,store)
local tween = value.tvalue;
-- adding event function
local function regFn(newValue,store)
if with then
newValue = with(newValue,item,store);
end
item[index] = newValue;
end
value.register(regFn);
-- this is using hacky of roblox instance
-- this is will keep reference from week table until
-- inscance got GCed
item:GetPropertyChangedSignal("ClassName"):Connect(function ()
return regFn;
end);
elseif (valueType == "function" or valueType == "table") and bind(item,index,value,valueType) then -- connect event
-- event binding

View file

@ -16,6 +16,7 @@ local function catch(...)
end
end
local week = {__mode = "vk"};
function module.init(shared)
local new = {};
local items = shared.items;
@ -92,7 +93,7 @@ function module.init(shared)
self.__self[key] = value;
local event = self.__evt[key];
if event then
for _,v in ipairs(event) do
for _,v in pairs(event) do -- NO ipairs here
wrap(catch)(v,value,store);
end
end
@ -112,6 +113,9 @@ function module.init(shared)
default = function (s,value)
return setmetatable({dvalue = value},{__index = s});
end;
tween = function (s,value)
return setmetatable({tvalue = value},{__index = s});
end;
key = key;
store = self;
t = "reg";
@ -126,7 +130,7 @@ function module.init(shared)
end
function new.new(self)
return setmetatable(
{__self = self or {},__evt = {},__reg = {}},store
{__self = self or {},__evt = setmetatable({},week),__reg = setmetatable({},week)},store
);
end