38
Root
6y

Preface: i'm pretty... definitely wasted. rum is amazing.

anyway, I spent today fighting with ActionCable. but as per usu, here's the rant's backstory:

I spent two or three days fighting with ActionCable a few weeks ago. idr how long because I had a 102*f fever at the time, but I managed to write a chat client frontend in React that hooked up to API Guy's copypasta backend. (He literally just copy/pasted it from a chat app tutorial. gg). My code wasn't great, but it did most of what it needed to do. It set up a websocket, had listeners for the various events, connected to the ActionCable server and channel, and wrote out updates to the DOM as they came in. It worked pretty well.

Back to the present!

I spent today trying to get the rest to work, which basically amounted to just fetching historical messages from the server. Turns out that's actually really hard to do, especially when THE FKING OFFICIAL DOCUMENTATION'S EXAMPLES ARE WRONG! Seriously, that crap has scoping and (coffeescript) syntax errors; it doesn't even run. but I didn't know that until the end, because seriously, who posts broken code on official docs? ugh! I spent five hours torturing my code in an effort to get it to work (plus however many more back when I had a fever), only to discover that the examples themselves are broken. No wonder I never got it working!

So, I rooted around for more tutorials or blogs or anything else with functional sample code. Basically every example out there is the same goddamn chat app tutorial with their own commentary. Remember that copy/paste? yeah, that's the one. Still pissed off about that. Also: that tutorial doesn't fetch history, or do anything other than the most basic functionality that I had already written. Totally useless to me.

After quite a bit of searching, the only semi-decent resource I was able to find was a blog from 2015 that's entirely written in Japanese. No, I can't read more than a handful of words, but I've been using it as a reference because its code is seriously more helpful than what's on official Rails docs. -_-

Still never got it to work, though. but after those five futile hours of fighting with the same crap, I sort of gave up and did something else.

zzz.

Anyway.
The moral of the story is that if you publish broken code examples beacuse you didn't even fking bother to test them first, some extremely pissed off and vindictive and fashionable developer will totally waterboard the hell out of you for the cumulative total of her wasted development time because screw you and your goddamn laziness.

Comments
  • 9
    oh. While trying to figure out why my code wasn't working, I sifted through the official Rails ActionCable package, and found a rather glaring bug. The function in question is `Subscription.prototype.perform(action, data)`

    If you call that and pass a string or number for `data` (anything that isn't a first-class javascript object, meaning something that accepts properties), it simply loses the "action" string prior to sending it to the server, so the server doesn't know wtf to do with it.

    here's the buggy snippet:
    ```if (data == null)
    data = {}
    data.action = action```

    Meaning if `data` is a string like "hello", it does `"hello".action = action` which obv isn't going to be very useful.

    Why didn't they just make a new object and assign both `action` and `data` as properties? Right, laziness!
  • 3
    I wish there was a "stuck" button to press when we are in the middle of these 5 hour long stretches trying to figure things out.

    Then we could all see in realtime all the other programmers out there pulling out what little hair they have left.
  • 3
    @Root so that means that when you get it to work properly (which I'm sure no one doubt that you will, and soon) you will write a blog post that actually explains more than basics and has good code? Maybe even in a somewhat interactive manner?
  • 3
    @Flygger I just might!

    Not a clue where I'd put it now, though.
  • 3
    @Root I'd suggest "the Internet" :o
  • 6
    Also, apparently a tiny problem with caching invalidation gives you a strange throwback! @Root
  • 1
    @rc5-asdf The issue is that the bugfix would be a breaking change, and would need to be patched on both the js and rails end. If either is out of sync, the connection wouldn't work.
  • 2
    @rc5-asdf Once I get it working, it'll be very useful!

    In-app support chat, in-app remote navigation, presence/status/load updates, etc.
Add Comment