Commits

Rune Halvorsen committed 7952794

Added an experimental parent property

Comments (0)

Files changed (1)

templates/js/js-message-classes.mako

   % if message.comment:
 ${INDENT}// ${message.comment}
   % endif
-cls.${service.name}["${version}"].${message.name} = function(arr)
+cls.${service.name}["${version}"].${message.name} = function(arr, parent)
 {
+  this.parent = parent || null;
   % for field in message.fields:
     % if field.doc:
 ${print_doc(field.doc, 1, INDENT)}
 ${INDENT}// ${field.comment}
     % endif
     % if field.q.name == "repeated":
+${INDENT}var self = this;
 ${INDENT}this.${field.name} = (arr[${str(field.number - 1)}] || []).map(function(item)
 ${INDENT}{
-${INDENT * 2}return new cls.${service.name}["${version}"].${field.typename()}(item);
+${INDENT * 2}return new cls.${service.name}["${version}"].${field.typename()}(item, self);
 ${INDENT}});
     % elif field.message and isinstance(field.message, proto.Message):
-${INDENT}this.${field.name} = arr[${str(field.number - 1)}] ? new cls.${service.name}["${version}"].${field.typename()}(arr[${str(field.number - 1)}]) : null;
+${INDENT}this.${field.name} = arr[${str(field.number - 1)}] ? new cls.${service.name}["${version}"].${field.typename()}(arr[${str(field.number - 1)}], this) : null;
     % else:
       % if field.message and isinstance(field.message, proto.Enum):
 ${INDENT}// cls.${service.name}["${version}"].${message.name}.${field.message.name}