jsBackingMapOrJsCopy function

JsMap jsBackingMapOrJsCopy(
  1. Map map
)

Returns a JsMap version of map, which will be either:

  • the backing JsMap if map is a JsBackedMap
  • a JsMap copy of map

This method is useful when the map needs to be passed to a JS function and you want to avoid copying it when possible.

If a copy is always needed, use JsBackedMap.from instead.

Implementation

JsMap jsBackingMapOrJsCopy(Map map) {
  // todo is it faster to just always do .from?
  if (map is JsBackedMap) {
    return map.jsObject;
  } else {
    return JsBackedMap.from(map).jsObject;
  }
}