getCodec method

String getCodec (
  1. DartType type
)

Implementation

String getCodec(DartType type) => registerCodecIfAbsent(type, () {
      if (type.isDynamic || type.isObject) {
        return 'DynamicCodec()';
      } else if (isJsInterface(lib, type)) {
        return 'JsInterfaceCodec<$type>((o) => $type.created(o))';
      } else if (isListType(type)) {
        final typeParam = (type as InterfaceType).typeArguments.first;
        return 'JsListCodec<$typeParam>(${getCodec(typeParam)})';
      } else if (isJsEnum(type)) {
        return createEnumCodec(type);
      } else if (type is FunctionType) {
        return createFunctionCodec(type);
      } else if (isMapType(type)) {
        final typeParam = (type as InterfaceType).typeArguments[1];
        return 'JsObjectAsMapCodec<$typeParam>(${getCodec(typeParam)})';
      }
      return null;
    });