exportable 0.1.0

The library provides the Exportable class - a mixin providing an ability to export objects to Maps or JSON. Useful for data models: storing in databases as Maps, or passing between client/server as JSON.

Properties of a class that is mixed with Exportable and wanted to be exportable should be annotated with @export, and could be

Usage example:

class Foo extends Object with Exportable {
  @export String bar;

void main() {
  Foo foo = new Exportable(Foo);
  // The same as
  // Foo foo = new Foo();
  foo.bar = 'Bar';
  // => {bar: Bar}
  // => {"bar":"Bar"}
  // => {"bar":"Bar"}
  Foo baz = new Exportable(Foo, '{"bar":"Baz"}');
  // The same as
  // Foo baz = new Foo();
  // baz.initFromJson('{"bar":"Baz"}');
  // => {"bar":"Baz"}
  Foo baz2 = new Exportable(Foo, {'bar': 'Baz'});
  // The same as
  // Foo baz2 = new Foo();
  // baz2.initFromMap({'bar': 'Baz'});
  // => {"bar":"Baz"}
Metadata: Dart VM vs dart2js #

Metadata annotations are used to

  • let the Exportable class know which properties could be exported or imported,
  • allow tree-shaking of a code.

When running in JS context, there are some difficulties with type detecting. So, here are some annotation rules.

If you plan to use exportable models with Dart VM only:

  • Each exportable property of an exportable class should be annotated with @export.
  • If you need a tree-shaking: annotate an exportable class itself. But this is not mandatory.

If you plan to use exportable models with dart2js:

  • Each exportable property of a JSON supported class should be annotated with @export.
  • Properties of a non JSON supported class (see JsonEncoder.convert()) should be annotated with @Export(<type>), where <type> is a type of a property.
  • Exportable class itself should be annotated with @export.
  • Provide more information/examples in the README.
  • Check why dart2js says "Hint: X methods retained for use by dart:mirrors out of X total methods (X%)" (seems like we have 1 retained method for one exportable class... is this a constructor?)
  • Write tests!

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  exportable: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:exportable/exportable.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.