toJSON static method

dynamic toJSON(
  1. dynamic track
)

Implementation

static toJSON(track) {
  var trackType = track.constructor;

  var json;

  // derived classes can define a static toJSON method
  if (trackType.toJSON != null) {
    json = trackType.toJSON(track);
  } else {
    // by default, we assume the data can be serialized as-is
    json = {
      'name': track.name,
      'times': AnimationUtils.convertArray(track.times, "List<num>"),
      'values': AnimationUtils.convertArray(track.values, "List<num>")
    };

    var interpolation = track.getInterpolation();

    if (interpolation != track.DefaultInterpolation) {
      json.interpolation = interpolation;
    }
  }

  json.type = track.ValueTypeName; // mandatory

  return json;
}