fix emitter typing issues
This commit is contained in:
parent
ecd018a9e1
commit
1e01c4c767
3 changed files with 17 additions and 15 deletions
|
|
@ -4,7 +4,7 @@
|
|||
version="1.1"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
@click="renderMessage"
|
||||
@click="emittMessage"
|
||||
>
|
||||
<AI />
|
||||
<MessageRenderer />
|
||||
|
|
@ -14,31 +14,35 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, ref, reactive, inject } from "vue";
|
||||
import MessageItem from "./UIDetails/messageItem.vue";
|
||||
import { defineComponent, ref, inject } from "vue";
|
||||
import AI from "../AI/index.vue";
|
||||
import InputItem from "./UIDetails/inputItem.vue";
|
||||
import TitleBar from "./UIDetails/titleBar.vue";
|
||||
import Messages from "./UIDetails/messages";
|
||||
import MessageRenderer from "./UIDetails/messageRenderer.vue";
|
||||
import { Mitt } from "@/types/mitt/index";
|
||||
export default defineComponent({
|
||||
name: "UIindex",
|
||||
components: { AI, MessageItem, InputItem, TitleBar, MessageRenderer },
|
||||
components: { AI, MessageRenderer, InputItem, TitleBar },
|
||||
setup() {
|
||||
const messages = Messages;
|
||||
const count = ref(0);
|
||||
const emitter: any = inject("mitt");
|
||||
|
||||
const renderMessage = () => {
|
||||
// imports mitt Emitter safely
|
||||
let emitter: Mitt;
|
||||
const emitterInject: Mitt | undefined = inject("mitt");
|
||||
if (emitterInject) emitter = emitterInject;
|
||||
|
||||
function emittMessage() {
|
||||
if (count.value < messages.length) {
|
||||
emitter.emit("renderMessage", messages[count.value])
|
||||
emitter.emit("renderMessage", messages[count.value]);
|
||||
count.value++;
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
renderMessage,
|
||||
emittMessage,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
|||
3
src/types/mitt/index.ts
Normal file
3
src/types/mitt/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import { Emitter } from "mitt";
|
||||
|
||||
export type Mitt = Emitter;
|
||||
|
|
@ -3,15 +3,10 @@
|
|||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, inject } from "vue";
|
||||
import { defineComponent } from "vue";
|
||||
import UIindex from "@/components/UI/index.vue";
|
||||
|
||||
export default defineComponent({
|
||||
name: "HomeIndex",
|
||||
components: { UIindex },
|
||||
setup() {
|
||||
const emitter: any = inject("mitt");
|
||||
emitter.on("newSelfMessage", (payload: any) => console.log("foo", payload));
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue