0

OK, so I am not sure how best to describe the problem. In the code below. There is a method called leaveRoom(room). This code when invoked tells a system to vacate a room, then join array object 0 as the current room by using the mentioned method. However it isnt doing the line this.setRoom(this.joinedRooms[0]);

I can tell you there is an object 0 in the joinedRooms.

Any idea what the syntax error is?

methods: {
connect () {
        setRoom(room) {
            this.$store.dispatch(RoomTypes.CURRENT_ROOM, room);
            this.currentRoom = room;
            this.$emit('onSelectRoom', room);
        },
        leaveRoom(room) {
            this.room = this.currentRoom; 
            this.$store.dispatch(RoomTypes.LEAVE_ROOM, room.id);
            Echo.leave("chat." + this.currentRoom.id);
            this.setRoom(this.joinedRooms[0]);
        }
    },
    created() {
        this.$store.dispatch(RoomTypes.GET_ROOMS);
    },
    computed: {
        ...mapGetters({ theme: "getTheme" }),
        joinedRooms() {
            return this.$store.state.rooms.joinedRooms;
        },
ArcticMediaRyan
  • 687
  • 8
  • 32
  • When you say it isn't doing that line, are you saying that line is not being invoked? You've verified by logging? – user2740650 Oct 11 '21 at 03:58
  • I m saying that line isnt correct. it SEEMS base on a bunch of console logs I HAD in there it was passing that line. What isnt happening is joinedRooms[0] doesnt seem to be valid because currentRoom doesnt change. – ArcticMediaRyan Oct 11 '21 at 04:00
  • Then it might be a similar issue to this React issue about not changing the instance of the array: https://stackoverflow.com/a/61896734/2740650 – user2740650 Oct 11 '21 at 04:02
  • Great Idea and you might be onto something but now I get "Uncaught TypeError: this.joinedRooms is not a function" – ArcticMediaRyan Oct 11 '21 at 04:09
  • That's progress. It's clearly something to do with the `this` pointer, but I'd suggest you update the code and ask specifically about that. I actually don't know that much about Vue :) – user2740650 Oct 11 '21 at 04:19
  • well it gives me an error which is nice HAHA. what I am confused about is when I console.log every step of it including the array it all looks right and SHOULD work – ArcticMediaRyan Oct 11 '21 at 04:32
  • Why don't u use mapState? – Amaarockz Oct 11 '21 at 04:42
  • @AmaarrockzI could not figure out how to write it - suggestions? – ArcticMediaRyan Oct 11 '21 at 04:48
  • 1
    dispatch is typically async. If your code to change rooms is async, then you have to wait for it before setting the room. – Jtcruthers Oct 11 '21 at 05:33
  • ^ This. "what I am confused about is when I console.log every step of it including the array it all looks right and SHOULD work " - see https://stackoverflow.com/questions/23392111/console-log-async-or-sync . The question doesn't contain enough things that could affect this, there should be no place for guesswork. Please, provide https://stackoverflow.com/help/mcve for your problem. – Estus Flask Oct 11 '21 at 07:24

0 Answers0