fix: remove use of assert module (#34)

* fix: remove use of assert module

The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native.

* chore: pr comments
This commit is contained in:
Alex Potsides
2020-02-17 21:19:14 +00:00
committed by GitHub
parent 6203109751
commit c77d8de2e7
2 changed files with 62 additions and 21 deletions

View File

@ -1,6 +1,5 @@
'use strict'
const assert = require('assert')
const withIs = require('class-is')
const Topology = require('./index')
@ -24,12 +23,21 @@ class MulticodecTopology extends Topology {
}) {
super({ min, max, handlers })
assert(multicodecs, 'one or more multicodec should be provided')
assert(handlers, 'the handlers should be provided')
assert(handlers.onConnect && typeof handlers.onConnect === 'function',
'the \'onConnect\' handler must be provided')
assert(handlers.onDisconnect && typeof handlers.onDisconnect === 'function',
'the \'onDisconnect\' handler must be provided')
if (!multicodecs) {
throw new Error('one or more multicodec should be provided')
}
if (!handlers) {
throw new Error('the handlers should be provided')
}
if (typeof handlers.onConnect !== 'function') {
throw new Error('the \'onConnect\' handler must be provided')
}
if (typeof handlers.onDisconnect !== 'function') {
throw new Error('the \'onDisconnect\' handler must be provided')
}
this.multicodecs = Array.isArray(multicodecs) ? multicodecs : [multicodecs]
this._registrar = undefined