toJSString static method
Implementation
static String toJSString(Map map) {
int i = 0;
Map placeHolders = {};
String keyPrefix = '__ensemble_placeholder__';
var encoded = jsonEncode(map, toEncodable: (value) {
if (value is JavascriptFunction) {
String key = keyPrefix + i.toString();
placeHolders[key] = value.functionCode;
i++;
return key;
}
throw JSException(1, 'Cannot convert to JSON: $value');
});
placeHolders.forEach((key, value) {
encoded = encoded.replaceFirst('\"$key\"', value);
});
return encoded;
}