Re: [web-nfc] What's the value of `toJSON()`? (#366)

A timid question. Wouldn't it be more clear if we had separate definitions for different record types?
Like in the example below (to be improved, but you get the idea).

```javascript
[Exposed=Window]
interface NDEFRecord {
  constructor(NDEFRecordInit recordInit);

  readonly attribute NDEFRecordType recordType;
  readonly attribute USVString mediaType;
  readonly attribute USVString id;
  readonly attribute DataView? data;
};

dictionary NDEFRecordInit {
  required NDEFRecordType recordType;
  USVString mediaType;
  USVString id;
  any data;
};

[Exposed=Window]
interface TextRecord: NDEFRecord {
  constructor(NDEFTextRecordInit recordInit);
  readonly attribute DOMString lang;
  readonly attribute DOMString encoding;
  USVString? text();  // for convenience
};
dictionary TextRecordInit: NDEFRecordInit {
  required NDEFRecordType recordType = "text";
  DOMString lang;
  DOMString encoding;
};

[Exposed=Window]
interface SmartPosterRecord: NDEFRecord {
  constructor(SmartPosterRecordInit init);
  sequence<NDEFRecord> toRecords();  // this could also be an attribute
};
dictionary SmartPosterRecordInit: NDEFRecordInit {
  required NDEFRecordType recordType = "smart-poster";
  sequence<NDEFRecord> records;
};

[Exposed=Window]
interface ExternalTypeRecord: NDEFRecord {
  constructor(ExternalTypeRecordInit init);
  sequence<NDEFRecord> toRecords();  // this should be a getter
  [NewObject] ArrayBuffer? arrayBuffer();
};
dictionary ExternalTypeRecordInit: NDEFRecordInit {
  required NDEFRecordType recordType = "external";
  sequence<NDEFRecord> records;  // nesting allowed; optional
};

// and so on for other types
```

OK, it's a lot to spec and implement.

-- 
GitHub Notification of comment by zolkis
Please view or discuss this issue at https://github.com/w3c/web-nfc/issues/366#issuecomment-542345558 using your GitHub account

Received on Tuesday, 15 October 2019 18:30:23 UTC