¡GoConqr estrena diseño! Cuéntanos qué te parece.

Módulo 10 de 18 · Multimedia

The subscribe method

Kostas Diakogiannis

The subscribe method

Subscribe function

What you have done is already impressive, but it can get a little bit better or more efficient to be more accurate. 

If you notice, after every dispatch, we want to take a look and see what the current state is, thus we print it the console. If you want something to happen after every dispatch is triggered, you can create a hook, by using the stores subscribe method. 

As shown above the subscribe method of a store accepts a callback function that will be executed any time a dispatch method of the same store is called, immediately after it.

Important note: You must define the subscribe BEFORE any dispatch, in order to see everything. The subscribe's callback will be executed every time a dispatch method, that has been defined AFTER subscription, is called. The previous ones will be ignored.

Instrucciones

Para avanzar en el curso, envía un intento de este test. Puedes enviarlo después de la última pregunta.

Ir al módulo elegido

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?