jsify function
Returns the JS implementation from Dart Object.
The optional customJsify function may return null to indicate,
that it could not handle the given Dart Object.
Implementation
dynamic jsify(
Object? dartObject, [
Object? Function(Object? object)? customJsify,
]) {
if (_isBasicType(dartObject)) {
if (dartObject == null) {
return null;
}
return dartObject;
}
if (dartObject is Iterable) {
return jsifyList(dartObject, customJsify);
}
if (dartObject is Map) {
var jsMap = util.newObject();
dartObject.forEach((key, value) {
util.setProperty(jsMap, key, jsify(value, customJsify));
});
return jsMap;
}
if (dartObject is Function) {
return allowInterop(dartObject);
}
Object? value = customJsify?.call(dartObject);
if (value == null) {
throw ArgumentError.value(dartObject, 'dartObject', 'Could not convert');
}
return value;
}