From 9a30eb2ca24c6fdbb67d433153b80f61d9a049fd Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 26 Mar 2014 02:03:13 -0700 Subject: [PATCH] get rid of wire.ext() --- README.md | 16 ++++++++-------- test/basic.js | 16 ++++++++-------- test/fetch.js | 18 +++++++++--------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 8e40920..88ec518 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,13 @@ net.createServer(function (socket) { // initialize the extension wire.use(ut_metadata()) - // all `ut_metadata` functionality can now be accessed at wire.ext('ut_metadata') + // all `ut_metadata` functionality can now be accessed at wire.ut_metadata // ask the peer to send us metadata - wire.ext('ut_metadata').fetch() + wire.ut_metadata.fetch() // 'metadata' event will fire when the metadata arrives and is verified to be correct! - wire.ext('ut_metadata').on('metadata', function (metadata) { + wire.ut_metadata.on('metadata', function (metadata) { // got metadata! // Note: the event will not fire if the peer does not support ut_metadata, if they @@ -68,7 +68,7 @@ net.createServer(function (socket) { // optionally, listen to the 'warning' event if you want to know that metadata is // probably not going to arrive for one of the above reasons. - wire.ext('ut_metadata').on('warning', function (err) { + wire.ut_metadata.on('warning', function (err) { console.log(err.message) }) @@ -87,7 +87,7 @@ net.createServer(function (socket) { Ask the peer to send metadata. ```js -wire.ext('ut_metadata').fetch() +wire.ut_metadata.fetch() ``` ### cancel @@ -95,7 +95,7 @@ wire.ext('ut_metadata').fetch() Stop asking the peer to send metadata. ```js -wire.ext('ut_metadata').cancel() +wire.ut_metadata.cancel() ``` ### event: 'metadata' @@ -104,7 +104,7 @@ Fired when metadata is available and verified to be correct. Called with a singl parameter of type Buffer. ```js -wire.ext('ut_metadata').on('metadata', function (metadata) { +wire.ut_metadata.on('metadata', function (metadata) { console.log(Buffer.isBuffer(metadata)) // true }) ``` @@ -121,7 +121,7 @@ Fired if: - the repeatedly sent invalid data ```js -wire.ext('ut_metadata').on('warning', function (err) { +wire.ut_metadata.on('warning', function (err) { console.log(err.message) }) ``` diff --git a/test/basic.js b/test/basic.js index 4f04a18..55f156e 100644 --- a/test/basic.js +++ b/test/basic.js @@ -12,10 +12,10 @@ test('wire.use(ut_metadata())', function (t) { wire.use(ut_metadata()) - t.ok(wire.ext('ut_metadata')) - t.ok(wire.ext('ut_metadata').fetch) - t.ok(wire.ext('ut_metadata').cancel) - t.notOk(wire.ext('ut_metadata').metadata) + t.ok(wire.ut_metadata) + t.ok(wire.ut_metadata.fetch) + t.ok(wire.ut_metadata.cancel) + t.notOk(wire.ut_metadata.metadata) t.end() }) @@ -25,9 +25,9 @@ test('wire.use(ut_metadata(metadata))', function (t) { wire.use(ut_metadata(metadata)) - t.ok(wire.ext('ut_metadata')) - t.ok(wire.ext('ut_metadata').fetch) - t.ok(wire.ext('ut_metadata').cancel) - t.equal(wire.ext('ut_metadata').metadata, metadata) + t.ok(wire.ut_metadata) + t.ok(wire.ut_metadata.fetch) + t.ok(wire.ut_metadata.cancel) + t.equal(wire.ut_metadata.metadata, metadata) t.end() }) diff --git a/test/fetch.js b/test/fetch.js index b82e112..9a9d66d 100644 --- a/test/fetch.js +++ b/test/fetch.js @@ -20,9 +20,9 @@ test('fetch()', function (t) { wire1.use(ut_metadata(metadata)) // wire1 already has metadata wire2.use(ut_metadata()) // wire2 does not - wire2.ext('ut_metadata').fetch() + wire2.ut_metadata.fetch() - wire2.ext('ut_metadata').on('metadata', function (_metadata) { + wire2.ut_metadata.on('metadata', function (_metadata) { // got metadata! t.deepEqual(_metadata, metadata) }) @@ -57,19 +57,19 @@ test('fetch() from peer without metadata', function (t) { wire1.use(ut_metadata()) // neither wire has metadata wire2.use(ut_metadata()) - wire2.ext('ut_metadata').fetch() + wire2.ut_metadata.fetch() - wire2.ext('ut_metadata').on('metadata', function () { + wire2.ut_metadata.on('metadata', function () { t.fail('No "metadata" event should fire') }) - wire1.ext('ut_metadata').onMessage = function () { + wire1.ut_metadata.onMessage = function () { t.fail('No messages should be sent to wire1') // No messages should be sent because wire1 never sent metadata_size in the // extended handshake, so he doesn't have metadata } - wire2.ext('ut_metadata').on('warning', function (err) { + wire2.ut_metadata.on('warning', function (err) { t.pass('got warning about peer missing metadata') }) @@ -103,13 +103,13 @@ test('discard invalid metadata', function (t) { wire1.use(ut_metadata(invalidMetadata)) wire2.use(ut_metadata()) - wire2.ext('ut_metadata').fetch() + wire2.ut_metadata.fetch() - wire2.ext('ut_metadata').on('metadata', function () { + wire2.ut_metadata.on('metadata', function () { t.fail('No "metadata" event should fire') }) - wire2.ext('ut_metadata').on('warning', function (err) { + wire2.ut_metadata.on('warning', function (err) { t.pass('got warning because peer sent reject too much') })