From 501f0d04371ebcdd9d9401d9e5b911b75f22ddef Mon Sep 17 00:00:00 2001
From: Cristiano Magro <cristiano.magro@vola.it>
Date: Mon, 30 Dec 2024 21:02:42 +0100
Subject: [PATCH] inject metodo al posto di usare emits per propagare un evento

---
 08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeBase.vue    |    4 +---
 08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/App.vue                         |    5 +++--
 08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeElement.vue |    3 ++-
 08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeGrid.vue    |    2 --
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/App.vue b/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/App.vue
index b993cb0..383aceb 100644
--- a/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/App.vue
+++ b/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/App.vue
@@ -4,7 +4,7 @@
       :topic-title="activeTopic && activeTopic.title"
       :text="activeTopic && activeTopic.fullText"
     ></active-element>
-    <knowledge-base @select-topic="activateTopic"></knowledge-base>
+    <knowledge-base ></knowledge-base>
   </div>
 </template>
 
@@ -34,7 +34,8 @@
   },
   provide(){
     return {
-      topics: this.topics
+      topics: this.topics,
+      selectTopic: this.activateTopic,
     }
   },
   methods: {
diff --git a/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeBase.vue b/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeBase.vue
index 563e530..ef95f5b 100644
--- a/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeBase.vue
+++ b/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeBase.vue
@@ -1,13 +1,11 @@
 <template>
   <section>
     <h2>Select a Topic</h2>
-    <knowledge-grid  @select-topic="$emit('select-topic', $event)"></knowledge-grid>
+    <knowledge-grid ></knowledge-grid>
   </section>
 </template>
 
 <script>
 export default {
- 
-  emits: ['select-topic'],
 };
 </script>
\ No newline at end of file
diff --git a/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeElement.vue b/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeElement.vue
index 143b1b0..0c2b76c 100644
--- a/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeElement.vue
+++ b/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeElement.vue
@@ -2,12 +2,13 @@
   <li>
     <h3>{{ topicName }}</h3>
     <p>{{ description }}</p>
-    <button @click="$emit('select-topic', id)">Learn More</button>
+    <button @click="selectTopic(id)">Learn More</button>
   </li>
 </template>
 
 <script>
 export default {
+  inject: ['selectTopic'],
   props: ['id', 'topicName', 'description'],
   emits: ['select-topic'],
 };
diff --git a/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeGrid.vue b/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeGrid.vue
index d2f423c..21dd630 100644
--- a/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeGrid.vue
+++ b/08 - component communication/cmp-communication-08-a-potential-problem-starting-setup/src/components/KnowledgeGrid.vue
@@ -6,7 +6,6 @@
       :id="topic.id"
       :topic-name="topic.title"
       :description="topic.description"
-      @select-topic="$emit('select-topic', $event)"
     ></knowledge-element>
   </ul>
 </template>
@@ -14,6 +13,5 @@
 <script>
 export default {
   inject: ['topics'],
-  emits: ['select-topic']
 };
 </script>
\ No newline at end of file

--
Gitblit v1.8.0