xxgreg / mustache

Mustache template Dart library
BSD 2-Clause "Simplified" License
57 stars 59 forks source link

[question] Any plans for moving over to reflectable? #26

Closed MikeMitterer closed 8 years ago

MikeMitterer commented 8 years ago

https://pub.dartlang.org/packages/reflectable

xxgreg commented 8 years ago

I'd like to. But I am swamped with work at the moment.

From memory all of the mirrors lives in renderer.dart. See: Renderer._getNamedProperty().

Credit to Michael Hixson who implemented the mirrors code.

  // Returns the property of the given object by name. For a map,
  // which contains the key name, this is object[name]. For other
  // objects, this is object.name or object.name(). If no property
  // by the given name exists, this method returns noSuchProperty.
  _getNamedProperty(object, name) {
    if (object is Map && object.containsKey(name)) return object[name];

    if (object is List && _integerTag.hasMatch(name)) return object[
        int.parse(name)];

    if (lenient && !_validTag.hasMatch(name)) return noSuchProperty;

    var instance = reflect(object);
    var field = instance.type.instanceMembers[new Symbol(name)];
    if (field == null) return noSuchProperty;

    var invocation = null;
    if ((field is VariableMirror) ||
        ((field is MethodMirror) && (field.isGetter))) {
      invocation = instance.getField(field.simpleName);
    } else if ((field is MethodMirror) && (field.parameters.length == 0)) {
      invocation = instance.invoke(field.simpleName, []);
    }
    if (invocation == null) {
      return noSuchProperty;
    }
    return invocation.reflectee;
  }
MikeMitterer commented 8 years ago

Hi, you saw my PR?

xxgreg commented 8 years ago

Thanks for the PR. Sorry about being slow to merge. I have a lot on my plate. I'm hoping to sort out PRs in my projects during the next week or two.

MikeMitterer commented 8 years ago

Thanks