ex_map 0.9.9

  • README.md
  • Example
  • Installing
  • Versions
  • --

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

example/example.dart

library example;

import 'dart:html';
import 'package:ex_map/ex_map.dart';

@ExMap
class ExampleMap extends ExtendedMap {
  @ExKey()
  int id;

  @ExKey(protected: true, type: int)
  int integerField = 1;

  @ExKey(type: String)
  var testField = 'test';
}

main() {
  ExampleMap exampleMap = new ExampleMap();
  exampleMap['id'] = 1;
  querySelector('body')
    ..appendText('keys: ${exampleMap.keys.toString()}')
    ..append(new Element.br())
    ..appendText('id: ${exampleMap.id}')
    ..append(new Element.br())
    ..appendText('integerField: ${exampleMap.integerField}')
    ..append(new Element.br())
    ..appendText('testField: ${exampleMap["testField"]}');
}

Use this package as a library

1. Depend on it

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


dependencies:
  ex_map: ^0.9.9

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:ex_map/ex_map.dart';
  
Version Uploaded Documentation Archive
0.10.2 Aug 15, 2016 Go to the documentation of ex_map 0.10.2 Download ex_map 0.10.2 archive
0.10.1 Aug 15, 2016 Go to the documentation of ex_map 0.10.1 Download ex_map 0.10.1 archive
0.9.9 Aug 14, 2016 Go to the documentation of ex_map 0.9.9 Download ex_map 0.9.9 archive
0.9.8 Aug 15, 2016 Go to the documentation of ex_map 0.9.8 Download ex_map 0.9.8 archive
Awaiting analysis to complete.