Command & Memento Patterns in Typescript (No BS TS Series 2 Episode 4)

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.พ. 2025

ความคิดเห็น • 48

  • @WesleyHandy
    @WesleyHandy 3 ปีที่แล้ว +16

    Folks, you will get the best out of these videos if you code along with him. Stop and start to keep up with the pace. But doing will really help solidify the principles.
    These are useful and helpful examples, Jack!

    • @jherr
      @jherr  3 ปีที่แล้ว +2

      Yes! Triple Yes! Yes! Yes! Yes!

  • @matthew1106
    @matthew1106 3 ปีที่แล้ว +22

    Jack you are killing it this year. You really are filling the void of intermediate/advanced topics in web dev ecosystem. Almost everything is beginner only.

    • @omarkarim9298
      @omarkarim9298 3 ปีที่แล้ว

      Couldn’t agree more, great level up channel

  • @robwatson826
    @robwatson826 2 ปีที่แล้ว +1

    This was one of my favourite videos of yours to date. A great topic and some really interesting (and surprisingly simple) implementations! Great stuff Jack

  • @aminomar7890
    @aminomar7890 3 ปีที่แล้ว +5

    His book “NO BS TS”, is very valuable, he is talented as a teacher too, I suffered a lot by jumping from place to place, there was no good explanation, missing important points, especially I am not that type who just keep digging without understanding the details, I wasted a lot of time till I found his valuable book.
    I can’t recommend it enough!

    • @jherr
      @jherr  3 ปีที่แล้ว +1

      Thank you so much!

    • @aminomar7890
      @aminomar7890 3 ปีที่แล้ว +1

      @@jherr I have noticed your clean code, that’s why I got your book, but I was surprised how it is well organised and easy to understand, because of the details and your method probably.
      thanks it was so helpful.

    • @aminomar7890
      @aminomar7890 3 ปีที่แล้ว +1

      @@jherr question please: about the updates , Is all I need to get the updates to click the link again ? I mean to get the updated version of the book.

    • @jherr
      @jherr  3 ปีที่แล้ว +1

      @@aminomar7890 Every time I put out a new chapter in the book you'll get an update in the email. The last update was last week. This week will not have a new No BS TS video, but the week after will, and you will get an update in the email a day before.

  • @kr30000
    @kr30000 3 ปีที่แล้ว +3

    Absolute perfection when it comes to explaining these topics with the examples, practical uses and different coding styles.
    I don't know if this would be useful as a future video idea, probably a very niche topic, but it could be cool to have the CommandStack tag each command with an id and maybe return the id on the execute method of the CommandStack class. It could extend the functionality to be able to undo only a specific command in the stack, or async undo. The `git revert` command comes to mind, but also other programs that show you the history of changes as a list to the side

    • @jherr
      @jherr  3 ปีที่แล้ว +1

      I was actually going to do that, but the example just got a little to complex to make for a reasonably comprehensible video.

  • @edgaremmanuel3197
    @edgaremmanuel3197 3 ปีที่แล้ว +2

    you are doing an awesome job.

  • @FilipCodes
    @FilipCodes 3 ปีที่แล้ว +2

    Wow awesome. Saved for later 😄

  • @VelizFrancia2012
    @VelizFrancia2012 2 ปีที่แล้ว +1

    just wow, thanks!

  • @mostafahamid9479
    @mostafahamid9479 3 ปีที่แล้ว +1

    Really professional

  • @ahmadalmasri1583
    @ahmadalmasri1583 3 ปีที่แล้ว +1

    you are the best

  • @info662
    @info662 3 ปีที่แล้ว +2

    Could we use Private class features instead? since they're truly private variables.
    Thanks a lot for your high quality content

    • @jherr
      @jherr  3 ปีที่แล้ว +1

      Yes, and I should have.

  • @Messirobben047
    @Messirobben047 3 ปีที่แล้ว +2

    Jack, Why does your terminal says ".... on (east -1)" ?

    • @jherr
      @jherr  3 ปีที่แล้ว +2

      Dude, I honestly don't know. 😂 It's just a Mac. It's not like I'm on AWS or anything. If you have any ideas lemme know.

    • @jherr
      @jherr  3 ปีที่แล้ว +1

      Actually, I think it's an interaction between the AWS dev tools and Oh-My-ZSH. I could remove that from my prompt. I'm just lazy.

  • @jemesmemes9026
    @jemesmemes9026 3 ปีที่แล้ว +1

    This should get added to the playlist. It's not in there yet.

    • @jherr
      @jherr  3 ปีที่แล้ว

      Very true, will do!

  • @eminqasimovdev
    @eminqasimovdev 3 ปีที่แล้ว +1

    When I see copilot autocompletes codes it blows my mind. I am on waitlist for a long time. but still they not give access to me.
    does someone know?

  • @笙于-g4c
    @笙于-g4c 3 ปีที่แล้ว +1

    Master, i have a question.What `s the difference between class type and function type? And is this programming style(implement with function) belonging to functional programming, or where can I learn this kind of functional writing style systematically

    • @jherr
      @jherr  3 ปีที่แล้ว

      I'm hesitant to say that it's "functional programming" since I'm not a functional programming expert.

  • @drvictor666
    @drvictor666 3 ปีที่แล้ว +1

    Amazing episode and series + I'm buying the book for xmass :)
    One question to the Command class implementation - why is the Command defined as an abstract class, rather than an interface which the command sub-classes would then implement rather than extend?

    • @jherr
      @jherr  3 ปีที่แล้ว

      If the base class isn't doing anything then you should use an abstract class. It just flattens the hierarchy and makes for more performant code.

    • @drvictor666
      @drvictor666 3 ปีที่แล้ว

      Well, if I have a concrete (non-abstract) class B which extends a concrete Class A, I won’t be able to say that B also `implements` an interface I if that one is defined as an abstract class. Because, while a class can `implement` any number of interfaces, it can `extend` only one parent.
      If the interface I is defined as an `interface` (a blueprint without any implementing code), you can still create an abstract class which would `implement` the interface, perhaps writing concrete code for some of the required methods while leaving the rest of them as `abstract` (thus, forcing the child classes to “complete” the implementation). This would also mean the original, un-related class B, which is from an entirely different family, can still skip the abstract class and implement the interface I directly in its own way.
      Unless, of course, I’m mistaken or waving around with outdated knowledge, eh, sweating already :)

  • @ItsAqib
    @ItsAqib 2 ปีที่แล้ว

    Which VS Code theme and fonts are you using in this video, Sir...??

    • @stephenbeattie
      @stephenbeattie 2 ปีที่แล้ว +1

      Check the comments on Jack's videos. He has this info and more.

  • @eminqasimovdev
    @eminqasimovdev 3 ปีที่แล้ว +3

    I think command pattern is more flexable than memento, most times you need interact with backend api. saving json state will not be helpfull in memento, with command you can easly define undo function (doing some async api requests)

  • @aminam9201
    @aminam9201 3 ปีที่แล้ว +1

    could you please mention the extension name for the sketch ?

    • @jherr
      @jherr  3 ปีที่แล้ว +1

      draw.io - marketplace.visualstudio.com/items?itemName=hediet.vscode-drawio

    • @aminam9201
      @aminam9201 3 ปีที่แล้ว +1

      ​@@jherr thanks, you are generous, helpful and awesome.

  • @georgekalogeropoulos1813
    @georgekalogeropoulos1813 3 ปีที่แล้ว +1

    Why do you not save it as json and you save it as string

    • @jherr
      @jherr  3 ปีที่แล้ว

      JSON is a string format.

  • @chauklaus2693
    @chauklaus2693 3 ปีที่แล้ว +3

    functional programming in JS/TS 🥺 please?

    • @francis_n
      @francis_n 3 ปีที่แล้ว

      yes would love to see this. Pleaase make functional programming videos Jack

  • @ngneerin
    @ngneerin 3 ปีที่แล้ว +2

    Please give examples where these patterns are used in real applications

    • @jherr
      @jherr  3 ปีที่แล้ว

      Sure, in this case it would be an Do/Undo/Redo feature. And you would see those in SPA applications like Figma, Google Docs, anything where you are editing something and want the customer to be able to recover from accidental edits.

    • @ngneerin
      @ngneerin 3 ปีที่แล้ว +1

      @@jherr most of these patterns are useful only on the frontend as you play with the same state. Backend could hardly use these. Because it's stateless or has its state stored in db. Correct me if I am wrong

    • @jherr
      @jherr  3 ปีที่แล้ว +4

      ​@@ngneerin I disagree. Thus far we have covered Factory, which is great for managing global configuration and resources (e.g. database connections) on the backend. Publish and Subscribe, which is an insanely powerful backend concept for doing workload distribution and doing workflow work. And Visitor and Iterator, which I used to do paged API access, which is very valuable in backend work for ETL and ML.

  • @NolanZewariligon
    @NolanZewariligon ปีที่แล้ว

    Simply exposing object's state publicly isn't the Memento pattern.
    Memento should be opaque to the public - no public API.
    Only the object who creates the memento should know how to handle it.
    Since TypeScript doesn't have friend classes like C++, I guess Memento should be a base class with everything private except the protected constructor that creates the memento metadata, and the method that reconstructs the state from memento-ed metadata.
    Then the class that derives the memento can expose the API to get and set mementos publicly without the public knowing anything about what's in the memento.
    And then another class can keep the reference to the derived class and be in charge of keeping mementos and undoing.