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

ValueAccessor and PropertyMap changes #19

Closed
navibyte opened this issue Apr 17, 2021 · 1 comment
Closed

ValueAccessor and PropertyMap changes #19

navibyte opened this issue Apr 17, 2021 · 1 comment
Labels
enhancement New feature or request refactoring 🗒️ attributes Related to the code package "attributes"

Comments

@navibyte
Copy link
Collaborator

navibyte commented Apr 17, 2021

Changes on ValueAccessor:

  • moved to package:attributes/values.dart
  • not implementing Counted any more
    • Some value accessors might not have size of values contained.
  • renamed accessor bool existsNull(K key);, was previously hasNull
    • Returns true if a value with key exists and that value is null.
  • new accessor bool existsNonNull(K key);
    • Returns true if a value with key exists and that value is non-null.
  • new accessor num getNum(K key, {num? min, num? max});
    • Returns a value of num type at key.
    • Still getInt and getDouble properties available too.
    • Use getNum when accessor might have either int or double property value.
  • new accessor num? tryNum(K key, {num? min, num? max});
    • similar as previous
    • but this returns null if if an underlying value is unavailable or cannot be converted to num.
  • changed accessor DateTime getTimeUTC(K key, {DateTime Function(Object?)? parse});
    • new parameter parse to define app specific conversion.
  • changed accessor DateTime? tryTimeUTC(K key, {DateTime Function(Object?)? parse});
    • new parameter parse to define app specific conversion.

Changes on ValueAccessorMixin

  • moved to package:attributes/values.dart
  • provides now default implementations only to accessor with "try" prefix
  • those now check for Exception not only FormatException

Example of ValueAccessorMixin method:

  @override
  String? tryString(K key) {
    try {
      return getString(key);
    } on Exception {
      return null;
    }
  }

New base interface for property collections (maps and lists)

abstract class Properties<K> extends ValueAccessor<K> implements Counted {
  PropertyMap getMap(K key);
  PropertyMap? tryMap(K key);
  PropertyList getList(K key);
  PropertyList? tryList(K key);
}

Changes on PropertyMap:

  • not anymore implementing ValueAccessor<String> directly
  • but via extending Properties<String>
  • removed factory PropertyMap.from(Map<String, dynamic> source)
  • new factory PropertyMap.decodeJson(String data)

Also new PropertyList that extends Properties<int>

@navibyte navibyte added enhancement New feature or request 🗒️ attributes Related to the code package "attributes" refactoring labels Apr 17, 2021
@navibyte
Copy link
Collaborator Author

Implemented on BETA-version 0.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring 🗒️ attributes Related to the code package "attributes"
Projects
None yet
Development

No branches or pull requests

0 participants