Skip to content

Commit

Permalink
New: Added oneofs: true to ConversionOptions, see #710
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Mar 20, 2017
1 parent 228c882 commit fe93d43
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
*/
converter.toObject = function toObject(mtype) {
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
var fields = mtype.fieldsArray;
var fields = mtype.fieldsArray.sort(util.compareFieldsById);
if (!fields.length)
return util.codegen()("return {}");
var gen = util.codegen("m", "o")
Expand Down Expand Up @@ -265,6 +265,9 @@ converter.toObject = function toObject(mtype) {
("}");
} else
genValuePartial_toObject(gen, field, i, prop);
if (field.partOf) gen
("if(o.oneofs)")
("d%s=%j", util.safeProp(field.partOf.name), field.name);
gen
("}");
}
Expand Down
1 change: 1 addition & 0 deletions src/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ Type.prototype.from = Type.prototype.fromObject;
* @property {boolean} [defaults=false] Also sets default values on the resulting object
* @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
* @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`
* @property {boolean} [oneofs=false] Includes virtual oneof properties set to the present field's name, if any
*/

/**
Expand Down

0 comments on commit fe93d43

Please sign in to comment.