Skip to content

Commit 0c6e639

Browse files
committed
Other: Added infrastructure for custom wrapping/unwrapping of special types, see #677
1 parent 3939667 commit 0c6e639

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: src/common.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ common("any", {
5151
type: "bytes",
5252
id: 2
5353
}
54-
}
54+
}/*,
55+
options: Object.create({
56+
__fromObject: function(object) {
57+
return this.fromObject(object);
58+
},
59+
__toObject: function(options) {
60+
return this.toObject(options);
61+
}
62+
})*/
5563
}
5664
});
5765

Diff for: src/type.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,18 @@ Type.prototype.setup = function setup() {
446446
types : types,
447447
util : util
448448
});
449-
this.fromObject = this.from = converter.fromObject(this).eof(fullName + "$fromObject", {
449+
this.fromObject = converter.fromObject(this).eof(fullName + "$fromObject", {
450450
types : types,
451451
util : util
452452
});
453+
if (this.options && this.options.__formObject)
454+
this.fromObject = this.options.__formObject.bind({ fromObject: this.fromObject });
453455
this.toObject = converter.toObject(this).eof(fullName + "$toObject", {
454456
types : types,
455457
util : util
456458
});
459+
if (this.options && this.options.__toObject)
460+
this.toObject = this.options.__toObject.bind({ toObject: this.toObject });
457461
return this;
458462
};
459463

0 commit comments

Comments
 (0)