mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-06-12 07:21:38 +00:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user