Skip to content
Luca Ubiali Web Developer

How to Contribute to Open Source - 4/13 - Build It Backwards

August 13th, 2024
Continuous Learning

Episode - https://laracasts.com/series/how-to-contribute-to-open-source/episodes/4


Now we are getting into the implementation of the new Prompts features. Luke takes an approach that I heard also being called “programming by wishful thinking”. Write your code as if the new features were already available, so you can focus on the high level APIs, rather than the underlying implementation.

In one of the playground files, there’s one that showcases all Prompts, so that’s a great example to copy/paste in a new file and edit it.

The new feature will be about allowing the user to define prompt steps that will be executed one after the other and will also allow users to back trace the steps.

1steps()
2 ->add(fn() => intro(...), revert: false)
3 ->add(fn() => suggest(...), revert: function() {...})
4 ->run()

With the add() method we can add a step. The main parameter is a closure that executes a prompt (or more than that if needed). It’s done as a closure because we need to be able to re-run each step if the user requests it.

The second parameter revert will define if the user can go back to that step. Typically it’s a boolean, but it can also be a closure. This can be useful when a step performs some logic we must undo on revert.

Not a single one of those method work, because they don’t exist. Next step will be actual implementation.