protocolbuffers / protocolbuffers/protobuf-javascript

[JS] Add `fromObject` method to take an AsObject type and return a T.

Offen
#11 5 Kommentare 12 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@lukesandberg arbeitet bereits daran.

Seit 11.3.2022.

bug javascript triaged
Vorherrschende Sprache
JavaScript
Sterne
471
Forks
91
Ø Merge
3 Std. 57 Min.
Gemergte PRs (30 T.)
2

Beschreibung

What language does this apply to?
JS/TS

Describe the problem you are trying to solve.
In JS, many different libraries expect to work with dictionaries, basically Record<A, B> or lists of these, to do things like state management in single page apps, list operations like find, slice, zip, etc. and more. Having the ability to freely move between a Message and a JSON object would make it MUCH easier to interoperate with different tools.

Currently, my message types get compiled to something like the following:

export class Polygon extends jspb.Message {
  // getters and setters here

  serializeBinary(): Uint8Array;
  toObject(includeInstance?: boolean): Polygon.AsObject;
  static toObject(includeInstance: boolean, msg: Polygon): Polygon.AsObject;
  static serializeBinaryToWriter(message: Polygon, writer: jspb.BinaryWriter): void;
  static deserializeBinary(bytes: Uint8Array): Polygon;
  static deserializeBinaryFromReader(message: Polygon, reader: jspb.BinaryReader): Polygon;
}

Describe the solution you'd like

  static fromObject(from: Polygon.AsObject): Polygon;

Describe alternatives you've considered
Writing a generic function to parse the field descriptors, but I don't know enough to make it work correctly, PLUS, it seems like a much better thing to be provided out of the box.

Additional context

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.