adding initing props class (no after setup) support, event.property => event.prop (namespace changed)

This commit is contained in:
세젤귀 고양이들 2021-12-17 19:43:57 +09:00
parent 40a9eccc75
commit 76eb260617
6 changed files with 103 additions and 41 deletions

View file

@ -1,15 +1,15 @@
local module = {};
local exportItemMeta = {
__index = function (self,key)
local methods = self.__methods;
local events = self.__events;
return (methods and methods[key]) or (events and events[key]) or (self.getters[key](self.__this));
end;
__newindex = function (self,key,value)
self.__setters[key](self.__this,value);
end;
};
-- local exportItemMeta = {
-- __index = function (self,key)
-- local methods = self.__methods;
-- local events = self.__events;
-- return (methods and methods[key]) or (events and events[key]) or (self.getters[key](self.__this));
-- end;
-- __newindex = function (self,key,value)
-- self.__setters[key](self.__this,value);
-- end;
-- };
function module.init(shared)
local new = {};
@ -26,6 +26,31 @@ function module.init(shared)
item = ClassName();
elseif classOfClassName == "table" then -- if classname is a calss what is included new function, call it for making new object (object)
local func = ClassName.new or ClassName.New or ClassName.__new;
if ClassName.__noSetup then -- if is support initing props
local childs,props = {},{...};
local parsed;
for iprop,prop in ipairs(props) do
for i,v in ipairs(prop) do
childs[i] = ((iprop == 1) and v or v:Clone());
prop[i] = nil;
end
if next(prop) then -- there are (key/value)s
if parsed then
for i,v in pairs(prop) do
prop[i] = v;
end
else
parsed = prop;
end
end
end
item = func(props);
local holder = (type(item) == "table") and (item.__holder or item.holder) or item;
for _,v in ipairs(childs) do
v.Parent = holder;
end
return item;
end
item = func();
end
if not item then -- if cannot make new object, ignore this call
@ -34,6 +59,7 @@ function module.init(shared)
end
-- set property and adding child and binding functions
local holder = (type(item) == "table") and (item.__holder or item.holder) or item; -- to __holder or holder or it self (for tabled)
for iprop,prop in pairs({...}) do
for index,value in pairs(prop) do
local valueType = typeof(value);
@ -44,11 +70,7 @@ function module.init(shared)
elseif indexType == "string" then
item[index] = value; -- set property
elseif indexType == "number" then -- object
if iprop == 1 then -- todo : move bindings
value.Parent = item;
else
value:Clone().Parent = item;
end
((iprop == 1) and value or value:Clone()).Parent = holder;
end
end
end
@ -75,17 +97,17 @@ function module.init(shared)
return this;
end
function new.export(newFn,setters,getters,methods,events) -- make quad importable class
return function ()
return setmetatable({
__this = newFn();
__setters = setters;
__getters = getters;
__methods = methods;
__events = events;
},exportItemMeta);
end;
end
-- function new.export(newFn,setters,getters,methods,events) -- make quad importable class
-- return function ()
-- return setmetatable({
-- __this = newFn();
-- __setters = setters;
-- __getters = getters;
-- __methods = methods;
-- __events = events;
-- },exportItemMeta);
-- end;
-- end
-- set module calling function
setmetatable(new,{

View file

@ -57,7 +57,7 @@ function module.init(shared)
-- property changed binding
local prefixProperty = prefix .. "Property::";
function new.property(name)
function new.prop(name)
return prefixProperty .. name;
end

View file

@ -24,11 +24,11 @@ frame{
]]
require = require(script.require);
local event = require("event");
local store = require("store");
local event = require("event"); ---@module "src.event"
local store = require("store"); ---@module "src.store"
--local style = require("style");
local class = require("class");
local mount = require("mount");
local class = require("class"); ---@module "src.class"
local mount = require("mount"); ---@module "src.mount"
function module.init()
local this = {items = {}};

View file

@ -19,7 +19,7 @@ end
function module.init(shared)
local new = {};
local items = shared.items;
local objSpace = {};
function objSpace:each(func)
for i,v in ipairs(self) do
@ -65,18 +65,22 @@ function module.init(shared)
return item and item[1];
end
--TODO: if item is exist already, ignore this call
function new.addObject(id,object)
local array = items[id];
if not array then
array = objSpace.__new();
items[id] = array;
function new.addObject(ids,object)
for id in ids:gmatch("[^,]+") do -- split by ,
-- remove trailing, heading spaces
id = id:gsub("^ +",""):gsub(" +$","");
local array = items[id];
if not array then
array = objSpace.__new();
items[id] = array;
end
insert(array, object);
end
insert(array, object);
end
local store = {};
function store:__index(key)
self.__self[key];
return self.__self[key];
end
function store:__newindex(key,value)
self.__self[key] = value;
@ -97,7 +101,7 @@ function module.init(shared)
end;
self.__reg[key] = register;
end
if func then
register(func);
end

View file

@ -1,5 +1,6 @@
-- 이렇게 모듈을 부를 수 있다, 뒤에 if 가 붇은것은 자동완성이 뜨도록 하기 위해서 사용된다
local quad = require(script.Parent.quad) if false then quad = require("src"); end
---@module "src/init.lua"
local quad = require(script.Parent.quad);
local render = quad.init();
-- init 함수를 이용해 여러 스크립트가 이 모듈을 호출해도 완전히 별계의
-- 환경에서 실행될 수 있도록 만든다, init 를 호출하면 완전히 새로운 store 와 style

35
testing.md Normal file
View file

@ -0,0 +1,35 @@
# 개채에 대해서 어떻게 저장하고 다시 불러오는가
글로벌 스토리지 계념이 있습니다
```lua
local quad = require(script.Parent.quad);
local render = quad.init();
local class = render.class;
local mount = render.mount;
local store = render.store;
local frame = class "Frame";
mount(script.Parent,
frame "PutIdHere" {
Size = UDim2.fromOffset(45,45);
frame "Child" {
Size = UDim2.fromOffset(45,45);
};
frame "Child" {
Size = UDim2.fromOffset(45,45);
};
frame "Child" {
Size = UDim2.fromOffset(45,45);
};
}
);
-- you can get first object by store.get Object
print(store.getObject "PutIdHere");
-- you can set objects properties like this
store.getObjects "Child".BackgroundColor = Color3.fromRGB(255,0,0);
-- you can get each child with forEach method
store.getObjects "Child":forEach(function (this)
print(this);
end);
```