avatarPatrícia Williams

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4376

Abstract

<span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> paymentService: PaymentService, <span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> moderationService: ModerationService </span>) {}

<span class="hljs-keyword">public</span> <span class="hljs-title function_">createPost</span>(<span class="hljs-attr">args</span>: <span class="hljs-title class_">CreatePostArgs</span>): <span class="hljs-title class_">Post</span> { <span class="hljs-keyword">const</span> post = <span class="hljs-variable language_">this</span>.<span class="hljs-property">postRepository</span>.<span class="hljs-title function_">create</span>(args);

<span class="hljs-variable language_">this</span>.<span class="hljs-property">reputationService</span>.<span class="hljs-title function_">increaseReputation</span>(args.<span class="hljs-property">userId</span>);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">notificationService</span>.<span class="hljs-title function_">notifyFollowersAboutPost</span>(post);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">userService</span>.<span class="hljs-title function_">updateUserActivity</span>(<span class="hljs-string">'post.created'</span>, post);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">trackingService</span>.<span class="hljs-title function_">registerTrackable</span>(<span class="hljs-string">'post'</span>, post);
<span class="hljs-variable language_">this</span>.<span class="hljs-property">moderationService</span>.<span class="hljs-title function_">checkPostContentForViolations</span>(post.<span class="hljs-property">content</span>);    

<span class="hljs-keyword">if</span> (args.<span class="hljs-property">isPremium</span>) {
  <span class="hljs-variable language_">this</span>.<span class="hljs-property">paymentService</span>.<span class="hljs-title function_">chargeUserForPremiumPost</span>(args.<span class="hljs-property">userId</span>);
}

<span class="hljs-keyword">return</span> post;

} }</pre></div><p id="154d">This example is obviously made up, so please don’t pay too much attention to the details. I just want you to notice how many services <code>PostService</code> is dependent on and imagine that these services may also be dependent on PostService. For example, the notification service may require additional data from the post service to dispatch notifications, or the <code>ModerationService</code> may need to modify the post again via <code>PostService</code> after moderation. This is where circular dependencies occur.</p><p id="96c0">So now that we have a grasp of the problem, let’s explore the solution that I want to propose.</p><h1 id="c471">The solution</h1><p id="72f0">The solution I want to propose for this problem is to use the well-known concept of Event-Driven Architecture. Instead of calling all subsequent actions from the <code>createPost</code> method, we will simply create the post there and emit an event. Then, any module interested in performing some action related to the event may do so without crossing its logical borders.</p><p id="53d2">NestJS already comes with handy tools that we can use to benefit from events. If you don't yet have the package installed, you can simply add <code>@nestjs/event-emitter</code> to your application.</p><div id="9629"><pre>yarn <span class="hljs-keyword">add</span> @nestjs/<span class="hljs-keyword">event</span>-emitter</pre></div><p id="32cf">And when the package is installed, add the <code>EventEmitterModule</code> to the root module of your application.</p><div id="e0ec"><pre><span class="hljs-keyword">import</span> { Module } <span class="hljs-keyword">from</span> <span class="hljs-string">'@nestjs/common'</span>; <span class="hljs-keyword">import</span> { EventEmitterModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@nestjs/event-emitter'</span>;

<span class="hljs-meta">@Module(<span class="hljs-params">{ imports: [ EventEmitterModule.forRoot(<span class="hljs-params"></span>), // ... ], }</span>)</span> export <span class="hljs-keyword">class</span> <span class="hljs-title class_">AppModule</span> {}</pre></div><p id="f073">When we have it ready, we may simply ge

Options

t rid of all <code>PostService</code> dependencies and replace them with only one — <code>EventEmitter2</code>. After this, we may also remove subsequent method invocations from the <code>createPost</code> method and instead emit an event with its key and payload. The payload may be defined as a separate interface or class if you wish, but here, for presentation purposes, I will just emit the created post as a payload.</p><div id="86c2"><pre><span class="hljs-keyword">class</span> <span class="hljs-title class_">PostsService</span> { <span class="hljs-title function_">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">private</span> eventEmitter: EventEmitter2</span>) {}

<span class="hljs-keyword">public</span> <span class="hljs-title function_">createPost</span>(<span class="hljs-attr">args</span>: <span class="hljs-title class_">CreatePostArgs</span>): <span class="hljs-title class_">Post</span> { <span class="hljs-keyword">const</span> post = <span class="hljs-variable language_">this</span>.<span class="hljs-property">db</span>.<span class="hljs-property">posts</span>.<span class="hljs-title function_">create</span>({ ... }); <span class="hljs-variable language_">this</span>.<span class="hljs-property">eventEmitter</span>.<span class="hljs-title function_">emit</span>(<span class="hljs-string">'post.created'</span>, post);

<span class="hljs-keyword">return</span> post;

} }</pre></div><p id="a801">The last thing we have to do is to add a listener to the modules that may be interested in this event. For example, in the notification module, we may have a listener as below. In the other modules, the code will be pretty much the same, just other services will be involved in event handling.</p><div id="c0ad"><pre><span class="hljs-keyword">class</span> <span class="hljs-title class_">NotificationsListener</span> { <span class="hljs-title function_">constructor</span>(<span class="hljs-params"> <span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> notificationsService: NotificationsService </span>) {}

<span class="hljs-meta">@OnEvent</span>(<span class="hljs-string">'post.created'</span>) <span class="hljs-title function_">handlePostCreated</span>(<span class="hljs-params">post: Post</span>) { <span class="hljs-variable language_">this</span>.<span class="hljs-property">reputationService</span>.<span class="hljs-title function_">notifyFollowersAboutPost</span>(post); } }</pre></div><p id="9b3f">This way, the <code>NotificationService</code> and <code>PostService</code> are only loosely coupled now. The <code>PostService</code> is no longer dependent on <code>NotificationService</code>. We get rid of circular dependency here, yet we keep the functionality still working — Yay!</p><h1 id="ea7f">Summary</h1><p id="bf46">To sum up, in this article we explored the proposition of introducing events into your application to solve the issue of circular dependencies. This approach helps modules to stay within their borders yet react to actions performed in another module as well. Even though this way may not be applicable to all solutions it definitely may fix the one presented today.</p><p id="c9dc">I want to say thank you to all who read this article. I would love to hear your thoughts about this proposal and your ways of tackling circular dependencies in your applications, so feel free to share.</p><p id="913c">Don’t forget to check out my other articles for more tips and insights. Happy hacking!</p><h1 id="7cf6">Stackademic 🎓</h1><p id="d5c3">Thank you for reading until the end. Before you go:</p><ul><li>Please consider <b>clapping</b> and <b>following</b> the writer! 👏</li><li>Follow us <a href="https://twitter.com/stackademichq"><b>X</b></a><b> | <a href="https://www.linkedin.com/company/stackademic">LinkedIn</a> | <a href="https://www.youtube.com/c/stackademic">YouTube</a> | <a href="https://discord.gg/in-plain-english-709094664682340443">Discord</a></b></li><li>Visit our other platforms: <a href="https://plainenglish.io"><b>In Plain English</b></a><b> | <a href="https://cofeed.app/">CoFeed</a> | <a href="https://venturemagazine.net/">Venture</a> | <a href="https://blog.cubed.run">Cubed</a></b></li><li>More content at <a href="https://stackademic.com"><b>Stackademic.com</b></a></li></ul></article></body>

How To Get Rid of Toxic People: A Step-By-Step Guide

Here’s everything you need to know to set boundaries and free yourself from manipulative, self-centered people.

Photo by averie woodard on Unsplash

Until a few years ago, my life was filled with toxic and dysfunctional people because I didn’t know how to say no.

As someone who was raised in a dysfunctional home with very strict parents, I thought I had to say yes to everything and everyone. I was trained to be a compliant soldier and follow the rules — not to stand up for myself and set boundaries.

So of course I attracted people who’d take advantage of my selfless personality. My lack of boundaries was convenient to them.

I eventually realized something had to change. I was chronically depleted because meeting my own needs was a foreign concept to me.

It was not an easy process, but now I can say that I’m a pro when it comes to setting boundaries. I can be assertive and express myself even when dealing with very manipulative, self-centered people.

If you relate to my story, keep reading — and I’ll show you exactly what you need to do to free yourself from toxic people.

Step 1. You Need To Feel Worthy of Setting Boundaries

Here’s the problem. Most of us don’t set boundaries because we don’t believe we have the right to set them.

Instead, we carry beliefs like:

  • “If I say no/set boundaries, I’m being selfish”;
  • “People will only love me and accept me if I’m agreeable and compliant”;
  • “I don’t deserve to express myself”;
  • “My worth is based on my ability to help others”.

The reality is that you’ll only be able to take care of yourself once you feel worthy of being taken care of. And you’ll only be able to set boundaries once you feel worthy of setting them.

Otherwise, how are you going to protect yourself from toxic people if you still think you don’t have the right to stand up for yourself? How are you going to be assertive if you don’t believe that your needs matter?

Exactly. You aren’t. Your limiting beliefs will come up to the surface, and you’ll think “who am I to do this?”.

So the first thing you have to do is embody the idea that you have every right to say no, prioritize your well-being, and meet your needs.

(P.S.: it won’t happen overnight. In the beginning, these beliefs will come up very often. However, the more you practice setting boundaries, the better you get at it).

Step 2. Get Clear On What You Need And Want

Sometimes we’re so eager to finally speak up and stop being taken advantage of, that our boundaries come across as weak or inconsistent because we never stopped to think about what we truly want and need first.

Saying no for the sake of saying no, or being rebellious for the sake of being rebellious will probably be counter-productive. Not only will your boundaries be disrespected, but you will probably feel guilty afterward.

First, you have to do some soul-searching. Ask yourself questions like,

  • Which relationships feel draining to me? What is lacking?
  • How does this person make me feel? And what do I want from this relationship?
  • How can I meet my own needs?

This way, your boundaries will come across as solid and secure because you’ve reconnected with your inner voice first — and now you’re able to effectively communicate your boundaries to others.

Sure, people will still feel threatened by your assertiveness, but you know how you deserve to be treated.

Step 3. Get Clear On Your Boundaries

Now is the time to create boundaries accordingly.

Examples:

1. You want to love and emotional intimacy, but your partner’s behavior is unstable and incoherent. They say they love you, but then push you away when things appear to be getting serious.

Some possible boundaries would be…

“I want a relationship with honesty and clear communication, and I feel like you avoid commitment/vulnerability. If you don’t want the same thing, let me know, because I don’t want to waste my time.”

“Hey, I love you and I want to have a committed relationship with you, but I can’t understand why you push me away sometimes. If you’re not ready for real intimacy, that’s okay, but please let me know. Don’t send me mixed signals. It’s not fair.”

2. You need alone time to be with yourself and process your feelings, but your parents keep coming over uninvited or calling all the time.

Some possible boundaries would be…

“I’m sorry, I can’t right now. Can we meet next week/this weekend?”

“Mom, I’d love to be with you but if you keep showing up without letting me know in advance, it’s very difficult to make time for you. From now on, please tell me something so I can organize my life.”

“I’m sorry, but I can’t drop everything I’m doing to help you/be with you. I have my own things. Can we meet in a few days?”

3. Your friend/boss/sibling is very manipulative. He twists the truth, makes passive-aggressive comments to minimize you, and doesn’t take responsibility for his actions. You’re tired of this behavior, and you want to be treated with respect.

Some possible boundaries would be…

“That’s not true. I know what happened, I’m not crazy. I’m not debating whether it happened or not.”

“If you you’re not willing, to be honest, I’m going to have to step away from this conversation.”

If you’d like to know more responses like these, highly recommend checking out this article.

Step 4. Set Those Boundaries

This is the hard part. Here’s what you need to know:

  • Don’t over-explain yourself. You will feel like you need to, but you don’t. Over-explaining opens a gap for others to manipulate you because they’ll realize you’re not sure of the boundaries you’re setting;
  • Remind yourself that boundaries are not a punishment — they’re a tool to feel respected and meet your emotional, physical, and spiritual needs;
  • You’ll still hear that voice inside you saying that you’re being too cold, insensitive, or demanding. All you have to do is acknowledge this voice and hold your boundaries anyway. As time goes by, you’ll feel worthy of the boundaries you’re setting.

And, most importantly…

Step 5. Keep Reinforcing Your Boundaries, Even (Especially) When People Disrespect Them (That’s What Toxic People Do)

The sad truth is, you can’t control whether or not people accept your boundaries. The only thing you can control is how you express yourself and what you do to meet your own needs.

Besides, your people-pleasing personality has been convenient to the toxic people in your life. They love that you can’t say no and want to please them at all costs.

When you start standing up for yourself, they will use whatever they can to get you to weaken your boundary. They will gaslight you, distort your memories, and call you crazy/selfish/insensitive. Their goal is to influence your behavior and change your new ways of being so that you get back to who you were before.

When you’re not sure of the boundaries you’re setting — when they don’t have strong roots within you — it can be tempting to fall into their trap. However, when your boundaries are rooted in your worthiness and self-love, you’ll be able to stand your ground.

At the end of the day, it’s not their reaction that determines how successful your boundary was — it’s your ability to stay grounded and true to yourself.

As I wrote before, many people will try to manipulate you into feeling guilty for being assertive and standing up for yourself.

If you back down instead of keeping your boundaries, they win.

I know expressing yourself and respecting your needs is not easy when you’re so used to prioritizing the needs of others. This is why it’s crucial to follow some rules and be kind to yourself.

Learning how to set boundaries takes time, effort, and courage, and it can be a very painful journey — but it’s all worth it in the end.

Ready to prioritize your well-being and change your life by setting empowering boundaries? In my Self-Healing Workbook, I share the exact process I went through to reclaim my self-respect and feel worthy of saying no and standing up for myself. Let’s do this together!

Self
Mental Health
Relationships
Toxic Relationships
Narcissism
Recommended from ReadMedium