

Noteapp public sharing code#
In earlier code, we passed pid as our first parameter to these functions but now we can remove that code because our process is identified by module name (Refer start_link function where _MODULE_ is one of the parameters.i.e all_notes(), create_note(note), get_note(id), delete_note(id),update_note(note).


We will not be passing any parameter so we will ignore the args parameter.This function will start the process by calling the GenServer.start_link() function which takes some argument.We are going to add our own start_link function The GenServer has the function start_link which is used to start the process.
Noteapp public sharing update#
def all_notes () # To list all notes def create_note (note) # To create note and will take struct as a parameter def get_note (id) # To get particular note def delete_note (id) # To delete particular note def update_note (note) #To update note and will take struct as a parameter That will be our four basic CRUD operations on the note. We are going to implement these callbacks and functionality.Developers are only required to implement the callbacks and functionality they are interested in. The documentation says GenServer behavior abstracts the common client-server interaction.use GenServer is a macro that adds GenServer behavior in this file.Inside the note_server.ex file add the following code.Create a file note_server.ex inside lib/note_app/notes.As promised in the introduction of this blog, we are going to create a Process Layer by using GenServer in it.Once, the project starts running navigate to localhost:4000 to see the welcome phoenix screen. Then navigate to project directory cd note_app and run mix phx.server.Note no mix.exs was found in the current directory if you get this error ** (Mix) The task "phx.new" could not be found.This can be done by running mix phx.new note_app -no-ecto -live.Once confirmed we need to create/generate Phoenix LiveView application.We can confirm this by running Elixir -v. First of all, our system should have Elixir installed.Part 2: We will build UI using Liveview and integrate the different layers we created in Part 1.Part 1: We will be generating the application and will add API Layer and Process Layer i.e Genserver (This is Part 1).This is obviously not an ideal scenario to use GenServer, but the purpose of this blog is to introduce LiveView and GenServer usage. We are going to use this state to manage our application state instead of using the database. The GenServer is a process that has its own state. Below screen recording is the entire flow of the project, this will give an idea of the project. Styling is very much similar to the app in that course. I got this inspiration from the Reactjs crash course I did on Udemy.
Noteapp public sharing mac#
Its UI will be similar to the Notes app in Mac OS. We are going to build a simple notetaking app with basic CRUD functionality. In this blog, we are going to harness the power and easiness of Liveview and GenServer. The library documentation itself says LiveView provides rich, real-time user experiences with server-rendered HTML. Phoenix Liveview is a new library that works with Phoenix and provides real-time user experiences with server-rendered HTML.
