Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Change so that setters and getters are outside of object #2

Open
LexiBigCheese opened this issue Aug 25, 2018 · 7 comments
Open

Comments

@LexiBigCheese
Copy link

a.dart

library lib.cool.a;

part "a.g.dart";

@serializable
class NiceClass {
  int numberOfNum = 3;
  String niceString = "apples";
}

a.g.dart

part of lib.cool.a;

ClassAccessor NiceClassAccessor = ClassAccessor(
  (NiceClass x) => ObjectAccessor<NiceClass>(
    getters: {
      "numberOfNum": () => x.numberOfNum,
      "niceString": () => x.niceString,
    },
    setters: {
      "numberOfNum": (int y) {x.numberOfNum = y;},
      "niceString": (String y) {x.niceString = y;},
    }
  ),
);
@luisvt
Copy link
Contributor

luisvt commented Sep 2, 2018

What would be the advantages?

That would means the user would not be able to access the attributes by string

var niceClass = NiceClass();

var numberOfNum = niceClass["numberOfNum"];

@LexiBigCheese
Copy link
Author

LexiBigCheese commented Sep 16, 2018

and it'd free up two operators. and they'd be able to get the attributes by string by NiceClassAccessor(niceClass)["numberOfNum"]

as well as being able to have a niceClass[3] and a freed up extends in class NiceClass {}

@luisvt
Copy link
Contributor

luisvt commented Sep 17, 2018

sorry, I still consider it does not worth it. Until the moment dart allows you to use multiple inheritance so you can extend from as many classes as you want.

@serializable
class NiceClass extends OtherClass with _$NiceClassSerializable {
...
}

for the case of accessing values by index you can still do:

numberOfNum.values[3]

@LexiBigCheese
Copy link
Author

Well... for now i'm working on my own fork of serializable_core which introduces the concept, and i'll try it out, see how it goes. I already have the classes in place, I just need to figure out the code generation. the way you just know how this all works is amazing.

@luisvt
Copy link
Contributor

luisvt commented Sep 24, 2018

maybe those changes should be introducen on built_mirrors instead of serializable since this looks more like a instance reflection than creating a serializable object

@luisvt
Copy link
Contributor

luisvt commented Sep 24, 2018

also maybe you would prefer take a look on reflectable

@LexiBigCheese
Copy link
Author

so you mean, merge mirrors + serializable? Because this would put serializable out of buisness but the code from serializable would be in mirrors. It sounds good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants