Let's talk about Events and Listeners

Поделиться
HTML-код
  • Опубликовано: 5 ноя 2024

Комментарии • 17

  • @brunosadventures3801
    @brunosadventures3801 5 дней назад +8

    For me working with events makes the code less understandable and readable. It is harder to find the code that is executed when a ticket is created. If you need more abstraction, just create an extra funtion or class with methods. Events can be handy for vendor packages where the event and listener code is not in the same repo.

  • @imqqmi
    @imqqmi 4 дня назад

    I'm a big fan of state machines. If you've got a complicated process flow with many branches and events, it's going to be a challenge to keep track of where things are within the workflow. A state machine allows you to keep track of the progress and it's easy to see where things get sent when or if it gets stuck.
    There are of course many ways to deal with this scenario but a spaghetti of events and listeners isn't at the top of my list.
    I've used this method (state machine) for a questionnaire for a research project where the target group had to fill in a questionnaire every 3 months for 18 months, each one with registration, MFA, introduction/instruction email, terms and services agreement email with link to accept it, email notifications, reminders (and keeping track if sent already and if it was successful), closing missed questionnaires, opening next questionnaires etc.
    The previous dev indeed had used events and listeners and it was a complete mess to debug or add/remove/disable steps. With state machine it was easy.

  • @Etcher
    @Etcher 11 часов назад

    Having this level of abstraction is always nice to have available but I've inherited projects where the previous dev(s) have used events and listeners in such a granular manner that while everything is neatly abstracted it is also a pain in the bum to debug or step through the code. The relationships between events and listeners are not always immediately apparent and it’s not always clear which listeners respond to an event without checking the EventServiceProvider first. Sometimes private methods in the Job class containing the business logic (in this case TicketPurchased and NewOrderPlaced) makes more sense as it is easier to trace what is happening where.

  • @kmbo_0
    @kmbo_0 5 дней назад

    I never tried to use Events or Listners before as I was doing everything inside my Action class, but after watching this video, I think I'll give it a try.
    Very well explained.

  • @khanra17
    @khanra17 3 дня назад

    Much much better audio than you usual Muddy low pitch audio!
    Good ✓

  • @Pekz00r
    @Pekz00r 5 дней назад +9

    I would strongly recommend against events and listeners in almost almost all cases. You should stick probably use Actions instead. The problem is that Events and listeners gets really messy and it is really hard to follow the code and see what side effects code has because events and listeners are too loosely coupled. If your actions gets too big and unwieldy, it is much better to just split your actions into several actions that calls each other instead.
    Jeffery Way explains this point very nicely in this video: ruclips.net/video/-ezOz6vPLoo/видео.html

    • @LaravelPHP
      @LaravelPHP  4 дня назад

      This is a great option! I think it really comes down to personal preference and what feels “messy” or “smooth” to you.
      But I agree sometimes an Action class can be perfect. ☺️
      -Josh

  • @pablold
    @pablold 4 дня назад

    It's a bit confusing for me to have the notification and the event sharing the same name, but nice example overall.

  • @matias.krabzik
    @matias.krabzik 5 дней назад +1

    Just in time! :D

  • @georgetulev3033
    @georgetulev3033 3 дня назад

    Good to know, but ...
    If not queued, the listeners execute inline, and if one fails, the rest won't execute. There you have it 'sometimes' it is not working!
    Just wait until someone decides to fire an event from the listener and then again and again. It's not fiction, just the paradise I live in

  • @code75581
    @code75581 5 дней назад

    Thanks for the video.
    Does the code inside the listener still run inside the job being processed ? If not what’s then the benefit of just abstracting The code ?

    • @mrozbarry
      @mrozbarry 5 дней назад

      I believe it would run in the same fpm process, but I'm not sure if it runs inline. Either way, the main purpose is so the flow of code is isolated, you could test the user notification event listener in isolation, and your job code would only need to assert that the event was dispatched.

  • @im_imon
    @im_imon 5 дней назад

    Which font and theme is it ?

  • @dominikbetlej7114
    @dominikbetlej7114 5 дней назад +1

    Thx!

  • @shaungbhone8368
    @shaungbhone8368 4 дня назад

    Nice Thumbnail

  • @helderneves91
    @helderneves91 5 дней назад

    nice ears men :D