Giter VIP home page Giter VIP logo

dart_functional_data's People

Contributors

ened avatar gabrielgarciagava avatar miguelcmedeiros avatar remonh87 avatar spkersten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dart_functional_data's Issues

Generics are not passed on

@FunctionalData()
class Generic<T> extends $Generic<T> {
    final T generic;

    const Generic({
        @required this.generic,
    });
}

generates:

abstract class $Generic {
  T get generic;
  const $Generic();
  Generic copyWith({T generic}) => Generic(generic: generic ?? this.generic);
  String toString() => "Generic(generic: $generic)";
  bool operator ==(dynamic other) =>
      other.runtimeType == runtimeType && generic == other.generic;
  @override
  int get hashCode {
    var result = 17;
    result = 37 * result + generic.hashCode;
    return result;
  }
}

But it should generate:

abstract class $Generic<T> {
  T get generic;
  const $Generic();
  Generic<T> copyWith({T generic}) => Generic(generic: generic ?? this.generic);
  ...
}

Problem with static const fields

When i try do something like
static const _minCnt = 1;
static const _maxCnt = 6;

class Model extends $Model {
  static const _minCnt = 1;
  static const _maxCnt = 6;
...

i got errorous implementation :

abstract class $Model {
  int get _minCnt;
  int get _maxCnt;
  const $Model();
  Model copyWith(
          {int _minCnt,
          int _maxCnt,

Class can't be used as mixin because it declares constructor...

in your sample:

@FunctionalData()
class Foo with $Foo {
  final int number;
  final String name;

  // Can't be const because of mixin
  Foo({this.number, this.name});
}

in real life i got error Class can't be used as mixin because it declares constructor...

@immutable
@FunctionalData()
class Base with $Base{
  final int uid;
  final int editTime;

  Base({this.uid, this.editTime});
}

Possible to generate `merge` and `apply` methods too?

Hi! First off, I love this package. It has solved so many problems for me.

My current use case is when a user signs in, I have their configuration for the app saved in Firebase. If it's their first time signing in, I have to populate it with reasonable empty fields. This is what that currently looks like:

// Configuration extends $Configuration and also uses json_serializable
//
// Inside document.get().then((snapshot) =>
final empty = Configuration.empty();

if (snapshot.exists) {
  final configuration = Configuration.fromJson(snapshot.data);

  await configurationDocument.setData(
    Configuration(
      primaryColor: configuration.primaryColor ?? empty.primaryColor,
      // A lot more fields . . .
    ).toJson(),
  );
} else {
  await configurationDocument.setData(empty.toJson());
}

With merge I think could just say something like:

await configurationDocument.setData(
  configuration.merge(empty).toJson()
);

Data generated violates 2 lint errors

When I generate code for the following class

@FunctionalData()
class Bar extends $Bar{
  Bar({this.foo});

  final String foo;
}

It results in:

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'bar.dart';

// **************************************************************************
// FunctionalDataGenerator
// **************************************************************************

// ignore_for_file: join_return_with_assignment
// ignore_for_file: avoid_classes_with_only_static_members
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: avoid_equals_and_hash_code_on_mutable_classes
abstract class $Bar {
  const $Bar();
  String get foo;
  Bar copyWith({String foo}) => Bar(foo: foo ?? this.foo);
  @override
  String toString() => "Bar(foo: $foo)";
  @override
  bool operator ==(dynamic other) =>
      other.runtimeType == runtimeType && foo == other.foo;
  @override
  int get hashCode {
    var result = 17;
    result = 37 * result + foo.hashCode;
    return result;
  }
}

class Bar$ {
  static final foo =
      Lens<Bar, String>((s_) => s_.foo, (s_, foo) => s_.copyWith(foo: foo));
}

This generated code has 2 violations to dart lint.

  • prefer_single_quotes (toString method)
  • always_specify_types (Lenses and hashcode)

I will submit a pr that will fix this.

Flutter types typed as dynamic

There's a weird bug that occurs when using flutter types.

...
import 'package:functional_data/functional_data.dart';
import 'package:flutter/material.dart';
...

part 'blend_mode.g.dart';

@FunctionalData()
class BlendModeData extends $BlendModeData {

    final BlendMode mode;

    const BlendModeData({
        @required this.mode,
    });

    const BlendModeData.deflt() : mode = BlendMode.srcOver;
}

would lead to

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'blend_mode.dart';

// **************************************************************************
// FunctionalDataGenerator
// **************************************************************************

abstract class $BlendModeData {
  dynamic get mode;
  const $BlendModeData();
  BlendModeData copyWith({dynamic mode}) =>
      BlendModeData(mode: mode ?? this.mode);
  String toString() => "BlendModeData(mode: $mode)";
  bool operator ==(dynamic other) =>
      other.runtimeType == runtimeType && mode == other.mode;
  @override
  int get hashCode {
    var result = 17;
    result = 37 * result + mode.hashCode;
    return result;
  }
}

class BlendModeData$ {
  static final mode = Lens<BlendModeData, dynamic>(
      (s_) => s_.mode, (s_, mode) => s_.copyWith(mode: mode));
}

Where mode should not be dynamic but BlendMode.

Everything works fine with non-flutter types.
Am I doing something wrong or is this a real issue?

Generics are ignored

For a class like:

class Holder<T>{
   final T t;
   Holder(this.t);
}

The generated Lenses remove the type parameter. It would be nice to have a lens of type Lens<Holder<T>,T> but instead we get Lens<Holder,T> which does not compile.

copyWith handles nulls incorrectly

hi,

final copyWith = '$className copyWith({${fields.map((f) => '${f.type} ${f.name}').join(', ')}}) => $className(${fields.map((f) => '${f.name}: ${f.name} ?? this.${f.name}').join(', ')});';

Generated code doesn't update nullable properties. E.g. x.copyWith(myProp: null) ignores myProp.

Support for null safety

Our reactive_ble library depends on functional_data. In order to successfully migrate our library to Dart null-safety. We need a null safety compatible version of Functional data.

Allow Analyzer version >= 0.39.0

Currently functional_data_generator have version constraints:
analyzer: ">=0.38.1 <0.39.0"

This creates issues with pub get and other dependencies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.