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() {}
@steph-crown
steph-crown / index.js
Last active October 28, 2024 14:59
A script to register a service worker
// Checks if we can use serviceWorker.
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("sw.js")
.then((registration) => {
// The registration wass successful
console.log("Service worker registered");
console.log(registration);
})
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