Preguntas Frecuentes Sobre Aurora IDO

No hay requerimientos específicos para unirse a SmartPad IDO, esta abierto para todos. Lo único que necesitas hacer es transferir algo de ETH a Aurora a través de Rainbow Bridge. La venta se…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Refactoring the Notifications Class

The API handles the interactions of students with their college application tasks and their counselors. Students can find colleges and scholarships to apply to, take tests to help guide them towards a career and keep track of their college application process through tasks specifically tailored for each college. Counselors can follow up with a student’s progress directly through messages and verifying their dashboard, and indirectly through a system of notifications.

The notification sending class has gone through many changes over the past two years, needing to do more and more to keep up with evolving requirements. As we now have a much better idea of what we need in a notifications system, and are starting to feel performance slowdown, it was time to do a ruthless analysis of the notification sending class, SendNotificationMixin.

This is what the notification sending class looked like before the refactor:

The issues I identified and wanted to address with the refactor:

Arguments

Logs

Complexity

The method is essentially in charge of creating three types of notifications:

While most events that trigger notifications in the app require all three types of notifications, an increasing number do not, and new requirements for mobile push notifications will mean removing even more push notifications. Based on this I’m planning to split this method into three separate methods that will each handle the creation of one single type of notification, and be called accordingly by methods generated by each event. A method called by an event will be responsible for knowing which types of notifications it needs to create.

Inheritance

Arguments (again)

Performance

An Excessively-large Object

Inheritance (again)

Standardization (or lack thereof)

In this first part of the refactor, I moved all the notification sending code out of the views, to make them smaller and easier to read. A typical notification sending view looked like this before the refactor:

(There are obviously other things that could be improved in post, but they are outside the scope of the notifications refactor so they will need to be addressed another time.)

I repeated this step for all of the other view classes, and created 22 new methods on SendNotificationMixin that handle the creation of notifications based on specific events.

We are now able to replace all instances in the code that look like this:

With a new environment variable that will hold the different values of the host for the different environments:

Add a comment

Related posts:

Puppy..

Everyday really is a blessing. To feel the warmth of the sun and the happiness of my puppy howling with excitement to see me. Love me, pat me I will not eat until you do. Your love means more to me…

Lesser Bugs with Static Type Checking in JavaScript with Flow

A major characteristic of JavaScript is that it has no types. It eases out learning and using JavaScript, but has two issues, it hampers performance and often results to more bugs. We cannot do…