How to Build a Calculator With Hotwire and No Javascript

Поділитися
Вставка
  • Опубліковано 6 вер 2024
  • In this video, I'll show you how you can build a calculator with Ruby on Rails' Hotwire, without any Javascript.
    🎥 Join my new Ruby on Rails Class here: mixandgo.com/r...
    👉 Buy my Bulletproof Ruby on Rails Applications eBook: j.mp/2OtFCdR
    Github Repository: github.com/mix...
    You can subscribe to the channel using this link: www.youtube.co...
    My website: mixandgo.com
    #rubyonrails #rails7 #hotwire #ruby #webdev

КОМЕНТАРІ • 13

  • @ritec
    @ritec 2 роки тому

    Great tutorial, thanks. Hotwire does have a ton of potential, the fact this was done without touching any JS is amazing.

  • @crengela
    @crengela 2 роки тому

    Thanks Cezar!

  • @kukunin1
    @kukunin1 2 роки тому

    Great videos, high quality! One improvement is to remove the #result attribute and simplify the rendering logic. #result can be replaced with just the left operand

  • @dudewhatthehellman
    @dudewhatthehellman 2 роки тому

    This seems almost absurdly complicated for what it is. Might make more sense to do it in JS but it’s good to know this option exists.

  • @edenlandau6426
    @edenlandau6426 2 роки тому +1

    This is cool, but wouldn't this be impractically slow across a network if you have to make a roundtrip for every button click?

    • @mixandgo
      @mixandgo  2 роки тому

      This particular example is slower because it responds with the entire page, but you can trim down the response to just the result div, which would very fast over websockets.
      I don't know what the exact benchmarks look like, but I would imagine the JS version would be faster to execute.

    • @PeterCooperUK
      @PeterCooperUK 2 роки тому +1

      It's reasonable to think that, but if you consider that a 3D multiplayer game is essentially doing a similar thing with hundreds of data points per second over a network, even 100 people simultaneously hammering away on a calculator like this is unlikely to tax a small server instance :)

  • @JuanVqz
    @JuanVqz 2 роки тому +1

    Thank you for sharing it, I wonder if it is possible to sum 1+49

    • @mixandgo
      @mixandgo  2 роки тому +1

      Sure, you'd have to change the logic a bit though. Maybe add an = sign to signify you're done adding numbers.

    • @volonterx
      @volonterx 2 роки тому +1

      I think next step is to replase array of values with a string that incremented with new symbol after a button click. This string also may be printed on the calculator screen. Backend should parse it to perform morse complex calculations.

  • @captaclientes3074
    @captaclientes3074 Рік тому

    what is your vscode theme?

    • @mixandgo
      @mixandgo  Рік тому +1

      I'm not 100%, sure, but I think it was "Community Material Palenight High Contrast".

    • @captaclientes3074
      @captaclientes3074 Рік тому

      @@mixandgo thanks!