simplifyVal<T extends HVal> function
T
simplifyVal<T extends HVal>(
- T val
Makes HVals more simpler, for commit call.
Makes ids (HRef) relative and removes dis part.
Implementation
T simplifyVal<T extends HVal>(T val) {
if (val is HRef) {
final newId = val.val.substring(val.val.lastIndexOf(':') + 1);
return HRef(newId) as T;
}
if (val is HGrid) {
var rows = val.map((row) => simplifyVal<HRow>(row)).toList();
return HGridBuilder.dictsToGrid(val.meta, rows) as T;
}
if (val is HRow) {
var newValues = val.values.map((v) {
if (v != null) {
return simplifyVal<HVal>(v);
} else {
return v;
}
}).toList();
return HRow(val.grid, newValues) as T;
}
if (val is HDict && val is! HHisItem) {
var newMap = <String, HVal?>{};
val.keys.forEach((key) {
final value = val[key];
if (value != null) {
newMap[key] = simplifyVal<HVal>(value);
} else {
newMap[key] = value;
}
});
return HDict(newMap) as T;
}
return val;
}