-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed: Types should not clear constructor with cache (fixes decorators)
- Loading branch information
Showing
7 changed files
with
93 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This example shows how decorators can be used with plain JavaScript. It's otherwise identical to | ||
// the README example. | ||
|
||
/*eslint-disable strict, no-console*/ | ||
var protobuf = require(".."); | ||
|
||
var Type = protobuf.Type, | ||
Field = protobuf.Field, | ||
OneOf = protobuf.OneOf; | ||
|
||
function AwesomeSubMessage(properties) { | ||
protobuf.Message.call(this, properties); | ||
} | ||
|
||
(AwesomeSubMessage.prototype = Object.create(protobuf.Message)).constructor = AwesomeSubMessage; | ||
|
||
Field.d(1, "string", "optional", "awesome default string")(AwesomeSubMessage.prototype, "awesomeField"); | ||
|
||
var AwesomeEnum = { | ||
ONE: 1, | ||
TWO: 2 | ||
}; | ||
|
||
Type.d("SuperAwesomeMessage")(AwesomeMessage); | ||
function AwesomeMessage(properties) { | ||
protobuf.Message.call(this, properties); | ||
} | ||
|
||
(AwesomeMessage.prototype = Object.create(protobuf.Message)).constructor = AwesomeMessage; | ||
|
||
Field.d(1, "string", "optional", "awesome default string")(AwesomeMessage.prototype, "awesomeField"); | ||
Field.d(2, AwesomeSubMessage)(AwesomeMessage.prototype, "awesomeSubMessage"); | ||
Field.d(3, AwesomeEnum, "optional", AwesomeEnum.ONE)(AwesomeMessage.prototype, "awesomeEnum"); | ||
OneOf.d("awesomeSubMessage", "awesomeEnum")(AwesomeMessage.prototype, "which"); | ||
|
||
// example code | ||
var message = new AwesomeMessage({ awesomeField: "hello" }); | ||
var buffer = AwesomeMessage.encode(message).finish(); | ||
var decoded = AwesomeMessage.decode(buffer); | ||
|
||
console.log(decoded, "internal name: " + AwesomeMessage.$type.name); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters