Skip to content

Commit

Permalink
Rename LongType.using.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtth committed Apr 12, 2016
1 parent 8ce9f61 commit 95ed285
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc
Submodule doc updated from e68f26 to 36b08f
12 changes: 8 additions & 4 deletions lib/types.js
Expand Up @@ -462,8 +462,8 @@ IntType.prototype.random = function () { return RANDOM.nextInt(1000) | 0; };
*
* We can't capture all the range unfortunately since JavaScript represents all
* numbers internally as `double`s, so the default implementation plays safe
* and throws rather than potentially silently change the data. See `using` or
* `AbstractLongType` below for a way to implement a custom long type.
* and throws rather than potentially silently change the data. See
* `LongType.__with` below for a way to implement a custom long type.
*
*/
function LongType() { PrimitiveType.call(this, 'long'); }
Expand Down Expand Up @@ -501,7 +501,7 @@ LongType.prototype._updateResolver = function (resolver, type) {
}
};
LongType.prototype.random = function () { return RANDOM.nextInt(); };
LongType.using = function (methods, noUnpack) {
LongType.__with = function (methods, noUnpack) {
methods = methods || {}; // Will give a more helpful error message.
// We map some of the methods to a different name to be able to intercept
// their input and output (otherwise we wouldn't be able to perform any
Expand All @@ -523,6 +523,10 @@ LongType.using = function (methods, noUnpack) {
});
return type;
};
LongType.using = util.deprecate(
LongType.__with,
'deprecated: use LongType.__with instead of LongType.using'
);

/**
* Floats.
Expand Down Expand Up @@ -1913,7 +1917,7 @@ LogicalType.prototype._resolve = utils.abstractFunction;
* Customizable long.
*
* This allows support of arbitrarily large long (e.g. larger than
* `Number.MAX_SAFE_INTEGER`). See `LongType.using` method above.
* `Number.MAX_SAFE_INTEGER`). See `LongType.__with` method above.
*
*/
function AbstractLongType(noUnpack) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "avsc",
"version": "3.4.1",
"version": "3.4.2",
"description": "Avro for JavaScript",
"homepage": "https://github.com/mtth/avsc",
"keywords": [
Expand Down
8 changes: 4 additions & 4 deletions test/test_types.js
Expand Up @@ -151,7 +151,7 @@ suite('types', function () {
});

test('using missing methods', function () {
assert.throws(function () { builtins.LongType.using(); });
assert.throws(function () { builtins.LongType.__with(); });
});

});
Expand Down Expand Up @@ -1777,7 +1777,7 @@ suite('types', function () {

suite('unpacked', function () {

var slowLongType = builtins.LongType.using({
var slowLongType = builtins.LongType.__with({
fromBuffer: function (buf) {
var neg = buf[7] >> 7;
if (neg) { // Negative number.
Expand Down Expand Up @@ -1857,7 +1857,7 @@ suite('types', function () {

suite('packed', function () {

var slowLongType = builtins.LongType.using({
var slowLongType = builtins.LongType.__with({
fromBuffer: function (buf) {
var tap = new Tap(buf);
return tap.readLong();
Expand Down Expand Up @@ -1903,7 +1903,7 @@ suite('types', function () {

test('incomplete buffer', function () {
// Check that `fromBuffer` doesn't get called.
var slowLongType = new builtins.LongType.using({
var slowLongType = new builtins.LongType.__with({
fromBuffer: function () { throw new Error('no'); },
toBuffer: null,
fromJSON: null,
Expand Down

0 comments on commit 95ed285

Please sign in to comment.