This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
export class MemoryLeakComponent implements OnInit, OnDestroy { | |
constructor(private readonly router: Router) {} | |
count = 0; | |
private sub: Subscription | undefined; | |
ngOnInit() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Memory Leak Example</h1> | |
<button (click)="navigate()">Go to Memory Leak Component</button> | |
<router-outlet></router-outlet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Routes } from '@angular/router'; | |
import { MemoryLeakComponent } from './memory-leak.component'; | |
export const routes: Routes = [ | |
{ path: 'memory-leak', component: MemoryLeakComponent }, | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnDestroy } from '@angular/core'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'], | |
}) | |
export class AppComponent implements OnInit { | |
constructor() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'], | |
}) | |
export class AppComponent implements OnInit { | |
constructor() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Hooks = { | |
UserMessages: { | |
mounted() { | |
let messages = []; | |
this.pushEvent("get_messages", {}, (response) => { | |
messages = response.messages; | |
this.unmount = mount( | |
this.el.id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder