Remove duplicate code in ConfigData.

This commit is contained in:
Joseph Cloutier
2023-12-21 01:14:57 -05:00
parent ca3012b877
commit 15e6dc5050

View File

@@ -34,39 +34,12 @@ abstract ConfigData(Dynamic) to Dynamic from Dynamic
public function exists(id:String):Bool
{
var tree = id.split(".");
if (tree.length <= 1)
{
return Reflect.hasField(this, id);
}
var current = this;
for (leaf in tree)
{
if (Reflect.hasField(current, leaf))
{
current = Reflect.field(current, leaf);
}
else
{
return false;
}
}
return true;
return get(id) != null;
}
public function get(id:String):ConfigData
{
var tree = id.split(".");
if (tree.length <= 1)
{
return Reflect.field(this, id);
}
var current = this;
for (leaf in tree)
@@ -87,17 +60,6 @@ abstract ConfigData(Dynamic) to Dynamic from Dynamic
var tree = id.split(".");
var array:Array<Dynamic> = null;
if (tree.length <= 1)
{
array = Reflect.field(this, id + ARRAY);
if (array == null && Reflect.hasField(this, id))
{
array = [Reflect.field(this, id)];
}
}
else
{
var current = this;
var field = tree.pop();
@@ -120,7 +82,6 @@ abstract ConfigData(Dynamic) to Dynamic from Dynamic
array = [Reflect.field(current, field)];
}
}
}
if (array != null)
{
@@ -415,24 +376,6 @@ abstract ConfigData(Dynamic) to Dynamic from Dynamic
public function push(id:String, value:Dynamic):Void
{
var tree = id.split(".");
if (tree.length <= 1)
{
if (Reflect.hasField(this, id))
{
if (!Reflect.hasField(this, id + ARRAY))
{
Reflect.setField(this, id + ARRAY, Reflect.hasField(this, id) ? [ObjectTools.deepCopy(Reflect.field(this, id))] : []);
}
var array:Array<Dynamic> = Reflect.field(this, id + ARRAY);
array.push(value);
}
Reflect.setField(this, id, value);
return;
}
var current = this;
var field = tree.pop();
@@ -471,13 +414,6 @@ abstract ConfigData(Dynamic) to Dynamic from Dynamic
public function set(id:String, value:Dynamic):Void
{
var tree = id.split(".");
if (tree.length <= 1)
{
Reflect.setField(this, id, value);
return;
}
var current = this;
var field = tree.pop();