Skip to content

Instantly share code, notes, and snippets.

View steph-crown's full-sized avatar
💻
Open to work

Stephen Emmanuel steph-crown

💻
Open to work
View GitHub Profile
// ...
export class MemoryLeakComponent implements OnInit, OnDestroy {
constructor(private readonly router: Router) {}
count = 0;
private sub: Subscription | undefined;
ngOnInit() {
import { Component } from '@angular/core';
import { Router, RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet],
templateUrl: './app.component.html',
styleUrl: './app.component.css',
})
<h1>Memory Leak Example</h1>
<button (click)="navigate()">Go to Memory Leak Component</button>
<router-outlet></router-outlet>
import { Routes } from '@angular/router';
import { MemoryLeakComponent } from './memory-leak.component';
export const routes: Routes = [
{ path: 'memory-leak', component: MemoryLeakComponent },
];
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { interval } from 'rxjs';
@Component({
selector: 'app-memory-leak',
template: `<div>
<p>Interval count: {{ count }}</p>
<button (click)="goBack()">Go back</button>
import { Component, OnDestroy } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
constructor() {}
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
constructor() {}
const Hooks = {
UserMessages: {
mounted() {
let messages = [];
this.pushEvent("get_messages", {}, (response) => {
messages = response.messages;
this.unmount = mount(
this.el.id,
defmodule AnonMessagesWeb.UserMessagesLive do
alias AnonMessages.Messaging
# ...
defp struct_to_map(struct) do
Map.from_struct(struct) |> Map.delete(:__meta__)
end
def handle_event("get_messages", _, socket) do
# get messages by recipient_id in descending order of inserted_at
def get_messages_by_recipient_id(recipient_id) do
from(m in Message, where: m.recipient_id == ^recipient_id, order_by: [desc: m.inserted_at])
|> Repo.all()
end