adding initing props class (no after setup) support, event.property => event.prop (namespace changed)
This commit is contained in:
parent
40a9eccc75
commit
76eb260617
6 changed files with 103 additions and 41 deletions
|
|
@ -1,15 +1,15 @@
|
||||||
local module = {};
|
local module = {};
|
||||||
|
|
||||||
local exportItemMeta = {
|
-- local exportItemMeta = {
|
||||||
__index = function (self,key)
|
-- __index = function (self,key)
|
||||||
local methods = self.__methods;
|
-- local methods = self.__methods;
|
||||||
local events = self.__events;
|
-- local events = self.__events;
|
||||||
return (methods and methods[key]) or (events and events[key]) or (self.getters[key](self.__this));
|
-- return (methods and methods[key]) or (events and events[key]) or (self.getters[key](self.__this));
|
||||||
end;
|
-- end;
|
||||||
__newindex = function (self,key,value)
|
-- __newindex = function (self,key,value)
|
||||||
self.__setters[key](self.__this,value);
|
-- self.__setters[key](self.__this,value);
|
||||||
end;
|
-- end;
|
||||||
};
|
-- };
|
||||||
|
|
||||||
function module.init(shared)
|
function module.init(shared)
|
||||||
local new = {};
|
local new = {};
|
||||||
|
|
@ -26,6 +26,31 @@ function module.init(shared)
|
||||||
item = ClassName();
|
item = ClassName();
|
||||||
elseif classOfClassName == "table" then -- if classname is a calss what is included new function, call it for making new object (object)
|
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;
|
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();
|
item = func();
|
||||||
end
|
end
|
||||||
if not item then -- if cannot make new object, ignore this call
|
if not item then -- if cannot make new object, ignore this call
|
||||||
|
|
@ -34,6 +59,7 @@ function module.init(shared)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set property and adding child and binding functions
|
-- 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 iprop,prop in pairs({...}) do
|
||||||
for index,value in pairs(prop) do
|
for index,value in pairs(prop) do
|
||||||
local valueType = typeof(value);
|
local valueType = typeof(value);
|
||||||
|
|
@ -44,11 +70,7 @@ function module.init(shared)
|
||||||
elseif indexType == "string" then
|
elseif indexType == "string" then
|
||||||
item[index] = value; -- set property
|
item[index] = value; -- set property
|
||||||
elseif indexType == "number" then -- object
|
elseif indexType == "number" then -- object
|
||||||
if iprop == 1 then -- todo : move bindings
|
((iprop == 1) and value or value:Clone()).Parent = holder;
|
||||||
value.Parent = item;
|
|
||||||
else
|
|
||||||
value:Clone().Parent = item;
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -75,17 +97,17 @@ function module.init(shared)
|
||||||
return this;
|
return this;
|
||||||
end
|
end
|
||||||
|
|
||||||
function new.export(newFn,setters,getters,methods,events) -- make quad importable class
|
-- function new.export(newFn,setters,getters,methods,events) -- make quad importable class
|
||||||
return function ()
|
-- return function ()
|
||||||
return setmetatable({
|
-- return setmetatable({
|
||||||
__this = newFn();
|
-- __this = newFn();
|
||||||
__setters = setters;
|
-- __setters = setters;
|
||||||
__getters = getters;
|
-- __getters = getters;
|
||||||
__methods = methods;
|
-- __methods = methods;
|
||||||
__events = events;
|
-- __events = events;
|
||||||
},exportItemMeta);
|
-- },exportItemMeta);
|
||||||
end;
|
-- end;
|
||||||
end
|
-- end
|
||||||
|
|
||||||
-- set module calling function
|
-- set module calling function
|
||||||
setmetatable(new,{
|
setmetatable(new,{
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ function module.init(shared)
|
||||||
|
|
||||||
-- property changed binding
|
-- property changed binding
|
||||||
local prefixProperty = prefix .. "Property::";
|
local prefixProperty = prefix .. "Property::";
|
||||||
function new.property(name)
|
function new.prop(name)
|
||||||
return prefixProperty .. name;
|
return prefixProperty .. name;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,11 @@ frame{
|
||||||
]]
|
]]
|
||||||
|
|
||||||
require = require(script.require);
|
require = require(script.require);
|
||||||
local event = require("event");
|
local event = require("event"); ---@module "src.event"
|
||||||
local store = require("store");
|
local store = require("store"); ---@module "src.store"
|
||||||
--local style = require("style");
|
--local style = require("style");
|
||||||
local class = require("class");
|
local class = require("class"); ---@module "src.class"
|
||||||
local mount = require("mount");
|
local mount = require("mount"); ---@module "src.mount"
|
||||||
|
|
||||||
function module.init()
|
function module.init()
|
||||||
local this = {items = {}};
|
local this = {items = {}};
|
||||||
|
|
|
||||||
|
|
@ -65,18 +65,22 @@ function module.init(shared)
|
||||||
return item and item[1];
|
return item and item[1];
|
||||||
end
|
end
|
||||||
--TODO: if item is exist already, ignore this call
|
--TODO: if item is exist already, ignore this call
|
||||||
function new.addObject(id,object)
|
function new.addObject(ids,object)
|
||||||
local array = items[id];
|
for id in ids:gmatch("[^,]+") do -- split by ,
|
||||||
if not array then
|
-- remove trailing, heading spaces
|
||||||
array = objSpace.__new();
|
id = id:gsub("^ +",""):gsub(" +$","");
|
||||||
items[id] = array;
|
local array = items[id];
|
||||||
|
if not array then
|
||||||
|
array = objSpace.__new();
|
||||||
|
items[id] = array;
|
||||||
|
end
|
||||||
|
insert(array, object);
|
||||||
end
|
end
|
||||||
insert(array, object);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local store = {};
|
local store = {};
|
||||||
function store:__index(key)
|
function store:__index(key)
|
||||||
self.__self[key];
|
return self.__self[key];
|
||||||
end
|
end
|
||||||
function store:__newindex(key,value)
|
function store:__newindex(key,value)
|
||||||
self.__self[key] = value;
|
self.__self[key] = value;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
-- 이렇게 모듈을 부를 수 있다, 뒤에 if 가 붇은것은 자동완성이 뜨도록 하기 위해서 사용된다
|
-- 이렇게 모듈을 부를 수 있다, 뒤에 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();
|
local render = quad.init();
|
||||||
-- init 함수를 이용해 여러 스크립트가 이 모듈을 호출해도 완전히 별계의
|
-- init 함수를 이용해 여러 스크립트가 이 모듈을 호출해도 완전히 별계의
|
||||||
-- 환경에서 실행될 수 있도록 만든다, init 를 호출하면 완전히 새로운 store 와 style
|
-- 환경에서 실행될 수 있도록 만든다, init 를 호출하면 완전히 새로운 store 와 style
|
||||||
|
|
|
||||||
35
testing.md
Normal file
35
testing.md
Normal 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);
|
||||||
|
```
|
||||||
Loading…
Reference in a new issue