2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-06-27 15:23:11 +00:00
This commit is contained in:
2022-02-17 18:06:02 +03:00
parent 8eb67ae4fb
commit 214785a893
27 changed files with 1645 additions and 396 deletions

View File

@ -45,7 +45,7 @@ export default class AutoList extends IEventHandler
add(value)
{
if (value instanceof IDestructible)
value.on("destroy", this._item_destroyed, this);
value.on("destroy", this.#_item_destroyed, this);
this.list.push(value);
@ -58,10 +58,10 @@ export default class AutoList extends IEventHandler
return;
if (value instanceof IDestructible)
value.on("destroy", this._item_destroyed, this);
value.on("destroy", this.#_item_destroyed, this);
if (this.list[index] instanceof IDestructible)
this.list[index].off("destroy", this._item_destroyed);
this.list[index].off("destroy", this.#_item_destroyed);
this.list[index] = value;
}
@ -99,14 +99,14 @@ export default class AutoList extends IEventHandler
var item = this.list[index];
if (item instanceof IDestructible)
item.off("destroy", this._item_destroyed);
item.off("destroy", this.#_item_destroyed);
this.list.splice(index, 1);
this._emit("remove", item);
}
_item_destroyed(sender)
#_item_destroyed = function(sender)
{
this.remove(sender);
}

View File

@ -39,7 +39,7 @@ export default class AutoMap extends IEventHandler
add(key, value)
{
if (value instanceof IDestructible)
value.on("destroy", this._item_destroyed);
value.on("destroy", this.#_item_destroyed);
this.dic[key] = value;
@ -58,13 +58,13 @@ export default class AutoMap extends IEventHandler
{
if (this.dic[key] !== undefined) {
if (this.dic[key] instanceof IDestructible)
this.dic[key].off("destroy", this._item_destroyed);
this.dic[key].off("destroy", this.#_item_destroyed);
delete this.dic[key];
}
}
_item_destroyed(sender)
#_item_destroyed = function(sender)
{
this.remove(sender);
}

View File

@ -276,9 +276,12 @@ export default class Codec {
var previous = null;
if (result == ResourceComparisonResult.Null)
if (result == ResourceComparisonResult.Empty) {
reply.seal();
return reply;
} else if (result == ResourceComparisonResult.Null) {
previous = new AsyncReply(null);
else if (result == ResourceComparisonResult.Local)
} else if (result == ResourceComparisonResult.Local)
{
previous = Warehouse.getById(data.getUint32(offset));
offset += 4;
@ -761,12 +764,19 @@ export default class Codec {
var template = Warehouse.getTemplateByClassId(classId, TemplateType.Record);
reply.arrayType = template.definedType;
reply.arrayType = template?.definedType;
var previous = null;
if (result == RecordComparisonResult.Null)
if (result == RecordComparisonResult.Empty)
{
reply.seal();
return reply;
}
else if (result == RecordComparisonResult.Null)
{
previous = new AsyncReply(null);
}
else if (result == RecordComparisonResult.Record
|| result == RecordComparisonResult.RecordSameType)
{
@ -806,7 +816,12 @@ export default class Codec {
let previous = null;
let classId = null;
if (result == RecordComparisonResult.Null)
if (result == RecordComparisonResult.Empty)
{
reply.seal();
return reply;
}
else if (result == RecordComparisonResult.Null)
previous = new AsyncReply(null);
else if (result == RecordComparisonResult.Record)
{
@ -820,7 +835,7 @@ export default class Codec {
}
reply.Add(previous);
reply.add(previous);
while (offset < end)
@ -856,7 +871,7 @@ export default class Codec {
}
reply.Seal();
reply.seal();
return reply;
// var reply = new AsyncBag();
@ -954,7 +969,7 @@ export default class Codec {
{
let record = new Record();
for (let i = 0; i < template.properties.Length; i++)
for (let i = 0; i < template.properties.length; i++)
record[template.properties[i].name] = ar[i];
reply.trigger(record);
@ -1002,11 +1017,12 @@ export default class Codec {
static composeRecordArray(records, connection, prependLength = false)
{
if (records == null || records?.length == 0)
if (records == null ) //|| records?.length == 0)
return prependLength ? new DC(4) : new DC(0);
var rt = new BinaryList();
var comparsion = Codec.compareRecords(null, records[0]);
//var comparsion = Codec.compareRecords(null, records[0]);
var comparsion = records.length == 0 ? RecordComparisonResult.Empty : Codec.compareRecords(null, records[0]);
rt.addUint8(comparsion);
@ -1101,11 +1117,11 @@ static isLocalResource(resource, connection) {
static composeResourceArray(resources, connection, prependLength = false) {
if (resources == null || resources.length == 0)// || !(resources instanceof ResourceArray))
if (resources == null)// || resources.length == 0)// || !(resources instanceof ResourceArray))
return prependLength ? new DC(4) : new DC(0);
var rt = new BinaryList();
var comparsion = Codec.compareResource(null, resources[0], connection);
var comparsion = resources.length == 0 ? ResourceComparisonResult.Empty : Codec.compareResource(null, resources[0], connection);
rt.addUint8(comparsion);

View File

@ -67,7 +67,7 @@ export default class DC extends Uint8Array
{
// convert hex to Uint8Array
var rt = new DC(value.length/2);
for(var i = 0; i < ar.length; i++)
for(var i = 0; i < rt.length; i++)
rt[i] = parseInt(value.substr(i*2, 2), 16);
return rt;
}
@ -295,6 +295,11 @@ export default class DC extends Uint8Array
return this.dv.getInt32(offset);
}
getInt32Little(offset)
{
return this.dv.getInt32(offset, true);
}
getUint32(offset)
{
return this.dv.getUint32(offset);
@ -506,6 +511,7 @@ export default class DC extends Uint8Array
return rt;
}
// @TODO: Test numbers with bit 7 of h = 1
getInt64(offset)
{
var h = this.getInt32(offset);

View File

@ -37,4 +37,8 @@ export default class Guid
{
return this.value.getHex(0, 16);
}
// [Symbol.toPrimitive](hint){
// console.log(hint);
// }
}

View File

@ -57,12 +57,16 @@ export default class KeyList
get(key)
{
if (key.valueOf != null)
key = key.valueOf();
for(var i = 0; i < this.keys.length; i++)
if (this.keys[i] == key)
return this.values[i];
if (this.keys[i].valueOf != null)
if (this.keys[i].valueOf() == key)
return this.values[i];
}
_item_destroyed(sender)
#_item_destroyed = function(sender)
{
for(var i = 0; i < this.values.length; i++)
if (sender == this.values[i])
@ -77,7 +81,7 @@ export default class KeyList
this.remove(key);
if (value instanceof IDestructible)
value.on("destroy", this._item_destroyed, this);
value.on("destroy", this.#_item_destroyed, this);
this.keys.push(key);
this.values.push(value);
@ -116,7 +120,7 @@ export default class KeyList
removeAt(index)
{
if (this.values[index] instanceof IDestructible)
this.values[index].off("destroy", this._item_destroyed);
this.values[index].off("destroy", this.#_item_destroyed);
this.keys.splice(index, 1);
this.values.splice(index, 1);

View File

@ -3,5 +3,6 @@ export default // const ResourceComparisonResult =
Null: 0,
Record: 1,
RecordSameType: 2,
Same: 3
Same: 3,
Empty: 4
};

View File

@ -3,5 +3,6 @@ export default // const ResourceComparisonResult =
Null: 0,
Distributed: 1,
Local: 2,
Same: 3
Same: 3,
Empty: 4
};

View File

@ -28,6 +28,10 @@
export default class Structure
{
toArray() {
return this.toPairs();
}
toPairs() {
var rt = [];
for (var i in this)