Skip to content

Instantly share code, notes, and snippets.

@el3um4s
el3um4s / Notification.svelte
Created October 15, 2022 14:01
MEDIUM - How To Show Notifications in Web Application - 07
<script>
import notifications from "./Notification";
</script>
@el3um4s
el3um4s / Notification.ts
Created October 15, 2022 14:00
MEDIUM - How To Show Notifications in Web Application - 06
import { writable } from "svelte/store";
import type { Writable } from "svelte/store";
const TIMEOUT = 3000;
type MessageType = "default" | "danger" | "warning" | "info" | "success";
export interface Msg {
type: MessageType;
message: string;
@el3um4s
el3um4s / Notification.ts
Created October 15, 2022 13:59
MEDIUM - How To Show Notifications in Web Application - 05
// ...
setTimeout(
() => {
notificationStore.update((n) => {
return n.filter((m) => m.id !== id);
});
},
msg?.timeout ? msg.timeout : TIMEOUT
);
// ...
@el3um4s
el3um4s / Notification.ts
Created October 15, 2022 13:59
MEDIUM - How To Show Notifications in Web Application - 04
const notifications = {
// ...
remove: (id: string) => {
notificationStore.update((n) => {
return n.filter((m) => m.id !== id);
});
},
};
@el3um4s
el3um4s / Notification.ts
Last active October 15, 2022 13:58
MEDIUM - How To Show Notifications in Web Application - 03
const notifications = {
// ...
send: (msg: Msg, id: string = idGenerator()) => {
notificationStore.update((n) => {
return [...n, { id, msg }];
});
},
};
@el3um4s
el3um4s / Notification.ts
Last active October 15, 2022 13:58
MEDIUM - How To Show Notifications in Web Application - 02
const idGenerator = (): string => "_" + Math.random().toString(36).substring(2, 9);
@el3um4s
el3um4s / Notification.ts
Created October 15, 2022 13:56
MEDIUM - How To Show Notifications in Web Application - 01
import { writable } from "svelte/store";
import type { Writable } from "svelte/store";
const TIMEOUT = 3000;
type MessageType = "default" | "danger" | "warning" | "info" | "success";
export interface Msg {
type: MessageType;
message: string;
@el3um4s
el3um4s / rollup.config.js
Created October 14, 2022 10:55
MEDIUM - How to update Rollup to version 3
import { spawn } from "child_process";
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
@el3um4s
el3um4s / rollup.config.js
Created October 14, 2022 10:54
MEDIUM - How to update Rollup to version 3
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
writeBundle() {
if (server) return;
@el3um4s
el3um4s / rollup.config.js
Created October 14, 2022 10:53
MEDIUM - How to update Rollup to version 3
import css from "@el3um4s/rollup-plugin-css-only";
import { terser } from "@el3um4s/rollup-plugin-terser";