From 71ffb0ebf115faf791c620836a74fefcf84fbca2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Magiera?= <magik6k@gmail.com>
Date: Wed, 19 Jun 2019 13:51:25 +0200
Subject: [PATCH] Use reflect.Type in node map

---
 basic.go | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/basic.go b/basic.go
index 12e746f..8a5c374 100644
--- a/basic.go
+++ b/basic.go
@@ -13,24 +13,22 @@ import (
 
 type bus struct {
 	lk    sync.Mutex
-	nodes map[string]*node
+	nodes map[reflect.Type]*node
 }
 
 func NewBus() Bus {
 	return &bus{
-		nodes: map[string]*node{},
+		nodes: map[reflect.Type]*node{},
 	}
 }
 
 func (b *bus) withNode(typ reflect.Type, cb func(*node), async func(*node)) error {
-	path := typePath(typ)
-
 	b.lk.Lock()
 
-	n, ok := b.nodes[path]
+	n, ok := b.nodes[typ]
 	if !ok {
 		n = newNode(typ)
-		b.nodes[path] = n
+		b.nodes[typ] = n
 	}
 
 	n.lk.Lock()
@@ -47,10 +45,8 @@ func (b *bus) withNode(typ reflect.Type, cb func(*node), async func(*node)) erro
 }
 
 func (b *bus) tryDropNode(typ reflect.Type) {
-	path := typePath(typ)
-
 	b.lk.Lock()
-	n, ok := b.nodes[path]
+	n, ok := b.nodes[typ]
 	if !ok { // already dropped
 		b.lk.Unlock()
 		return
@@ -64,7 +60,7 @@ func (b *bus) tryDropNode(typ reflect.Type) {
 	}
 	n.lk.Unlock()
 
-	delete(b.nodes, path)
+	delete(b.nodes, typ)
 	b.lk.Unlock()
 }
 
@@ -201,8 +197,4 @@ func (n *node) emit(event interface{}) {
 ///////////////////////
 // UTILS
 
-func typePath(t reflect.Type) string {
-	return t.PkgPath() + "/" + t.String()
-}
-
 var _ Bus = &bus{}