mclintprojects / actioncable-vue

A Vue plugin that makes integrating Rails Action Cable dead-easy.
MIT License
181 stars 38 forks source link

How to access the component from inside of received()? #1

Closed kevinelliott closed 5 years ago

kevinelliott commented 5 years ago

I would like to call methods defined in the component that subscribed to the channel. How can I access this.something() from the received(data) event handler?

mclintprojects commented 5 years ago

Hello @kevinelliott! What version of the library are you using? If it's not v1.2.4 please update to v1.2.4.

kevinelliott commented 5 years ago

Hi @mclintprojects ... yes, I'm using 1.2.4.

actioncable-vue@^1.2.4:
  version "1.2.4"
  resolved "https://registry.yarnpkg.com/actioncable-vue/-/actioncable-vue-1.2.4.tgz#8df6a244c2ba04847295f07575b3c7428f000e76"
  dependencies:
    actioncable "^5.2.2"
mclintprojects commented 5 years ago

@kevinelliott I just checked and it works. You should be able to do this.something() and have it work just fine. Can I please see a snippet of your code?

channels: {
    ChatChannel: {
      received(data) {
        switch (data.type) {
          case "new_message":
            this.updateConvo(data.payload);
            break;

          case "new_convo":
            this.addConvo(data.payload);
            break;
        }
      }
    }
  }

That's a snippet of my code and it works fine.

mclintprojects commented 5 years ago

Hi @kevinelliott, I'm closing this issue because everything seems to be in order. Let me know if otherwise.