Esta demasiado bueno este curso
Introducci贸n a SolidJS
Los problemas que resuelve SolidJS
Instalaci贸n de SolidJS: usando un template para nuestra aplicaci贸n
Primitiva reactiva de SolidJS: signals
Primitiva reactiva de SolidJS: effect
Primitiva reactiva de SolidJS: memo
Quiz: Introducci贸n a SolidJS
Reactividad a profundidad
驴Qu茅 es la reactividad?
Crea tu propia libreria reactiva: MiniSolid
Signals aplicados a un proyecto
Effects aplicados a un proyecto
Crea mejores aplicaciones con signals derivados
Memos aplicados a un proyecto
Renderizado de un proyecto en SolidJS
Quiz: Reactividad a profundidad
Renderizado en Solid
ToDo App: usando reactividad y sistemas de renderizado en un proyecto
Implementando el Dark Mode a un proyecto
Renderizado Condicional
Renderizado de Listas
Manejo de Eventos
Quiz: Renderizado en Solid
Reactividad en Listas
Reactividad en Listas
Stores para optimizar renderizados
Como implementar Stores a un proyecto
Funci贸n Produce para usar sintaxis de Javascript
Quiz: Reactividad en Listas
Componentes
驴Qu茅 son componentes en SolidJS?
Usando Props para comunicaci贸n entre componentes de una aplicaci贸n
Manejando eventos en una aplicaci贸n SolidJS
Guarda el estado de una aplicaci贸n con LocalStorage
Deploy de la aplicaci贸n ToDo con Netlify
Comparte tu proyecto con la comunidad
Quiz: Componentes
You don't have access to this class
Keep learning! Join and start boosting your career
In the world of reactive web libraries, effects play a crucial role. Systems like React, Vue or Solid use the effects primitive to handle changes and reactions in their internal architectures. But what does an effect really mean in this context? Basically, effects are functions that are executed in response to changes in signals, allowing automatic updates and working in collaboration with other components such as interface rendering. This concept is vital for integrating and keeping the different elements of an application up to date as data changes.
To create an effect, Solid uses the createEffect
function, which follows a very clear syntax. The main idea is to set up a function that acts on changes in signals, which we refer to as side effects. These effects depend on reactive variables, called signals. Let's see how to code it:
import { createEffect } from 'PlatziSolids';
createEffect(() => { console.log(count); // 'count' is a signal});
This function ensures that whenever the signal count
changes, the function inside createEffect
will be executed, logging the modifications that occur.
In Solid, the global context and the stack take an essential role in its reactivity algorithm. This stack system works as a temporary storage that manages the communication between signals and effects. The stack acts as a stack (LIFO - Last In, First Out), where effects and their functions are inserted and executed sequentially.
The way these elements interact is by managing a global context. As effects are executed, they are added to the stack. This approach allows for indirect but efficient communication between signals and effects. This means that each time an effect is executed, the last element inserted in the stack, known as observer, is taken into account.
When an effect uses a signal, it automatically becomes a subscriber of that signal. This relationship allows that every time the signal changes, all the effects that are listening to it are executed again. This communication is done using a data structure called set, which handles single elements efficiently:
const subscribers = new Set();
subscribers.add(observer);
This set acts as a list of subscribers. When a signal is modified, all subscribers are notified to execute the corresponding functions again, thus allowing the automatic update of states in the application.
To verify that effects work correctly, we can incorporate them in our applications by simple tests. For example:
createEffect(() => { const element = document.getElementById('count'); element.textContent = countSignal;});
This code block is executed when the signal countSignal
changes, automatically updating the content of the DOM element with the id count.
In this way, you can see how both the log consoles and the interface changes are automatically synchronized when the signal is modified.
Learning about the effects on reactive systems like Solid not only enriches the knowledge of modern web development, but also prepares developers to enter projects where reactivity is an essential component. Go ahead! Keep exploring and understanding more about these fascinating systems.
Contributions 3
Questions 0
Esta demasiado bueno este curso
Una joya de clase 馃殌
Want to see more contributions, questions and answers from the community?