ex_map 0.9.9 copy "ex_map: ^0.9.9" to clipboard
ex_map: ^0.9.9 copied to clipboard

outdatedDart 1 only

A library for writing pretty simple object class with Map interface.

Build Status

With the object easier to work when he has a good Map api. Such an object is serialized and deserialized well. The class constructor can be designated properties of map and types, and properties be designed with get and set:

class TestMap extends ExtendedMap {
  TestMap({id, integerField, testField}) {
    /// The property can not be set differently than through special method
    protectedKeys.add('id');
    types = {'testField': String, 'integerField': int};
  }

  /// The property can be established only through the operator: "."
  get id => this['id'];
  set id(value) => setProtectedField('id', value);

  get integerField => this['integerField'];
  set integerField(value) => this['integerField'] = value;

  get testField => this['testField'];
  set testField(value) => this['testField'] = value;
}

TestMap map;

setUp(() {
  map = new TestMap();
});

test('has protected fields', () {
  map.id = 1;
  expect(map['id'], equals(1));
  try {
    map['id'] = 2;
  } catch (error) {
    expect((error as ArgumentError).message, equals("id can't be changed"));
  }
});

test('has right types', () {
  map.integerField = 1;
  expect(map['integerField'], equals(1));

  map['testField'] = 2;
  expect(map.testField, equals('2'));
});

test('has a map interface', () {
  map.testField = 'test';

  expect(map.testField, equals('test'));
  expect(map['testField'], equals('test'));
});

Annotation for transformer: #

/// original source    =>   be transformed to   =>   ready for use 
import 'package:ex_map/ex_map.dart';      ///    import 'package:ex_map/ex_map.dart';
                                          ///
@ExMap                                    ///    @ExMap
class ExampleMap extends ExtendedMap {    ///    class ExampleMap extends ExtendedMap {
  @ExKey()                                ///
  int id;                                 ///       ExampleMap({int id, int integerField, String testField}) {
                                          ///         protectedKeys.addAll(['integerField']);
  @ExKey(protected: true, type: int)      ///         types = {'id': int, 'integerField': int, 'testField': String};
  int integerField = 1;                   ///         this.integerField = 1;
                                          ///         this['testField'] = 'test';
  @ExKey(type: String)                    ///       }
  var testField = 'test';                 ///       
}                                         ///       get id => this['id'];
                                          ///       set id(value) => this['id'] = value;
                                          ///
                                          ///       get integerField => this['integerField'];
                                          ///       set integerFieldd(value) => setProtectedField('integerField', value);
                                          ///
                                          ///       get testField => this['testField'];
                                          ///       set testField(value) => this['testField'] = value;
                                          ///    }

TODO:

  • Default constructor check in transformer
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A library for writing pretty simple object class with Map interface.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

barback

More

Packages that depend on ex_map