Skip to content

Instantly share code, notes, and snippets.

<script>
import {subscribe, publish} from './pubsub';
import {onMount} from 'svelte';
import {ItemAddEvent, ItemRemoveEvent, CartChangesEvent} from './project-events'
import { Product, Cart } from './Cart'
let cart = new Cart();
let cartData = []
let total =0
<script>
import {publish, subscribe} from './pubsub'
import {onMessageEvent} from './project-events'
import {onMount} from 'svelte'
let message;
//Listen the event onMount and unscubscribe when return.
onMount(()=>{
let onMsg = subscribe(onMessageEvent, (msg)=>{
const eventMap = new Map();
export function publish(event){
let eventName = event.constructor.name
if(eventName && eventMap.has(eventName)){
eventMap.get(eventName).forEach(listener => listener(event.args))
}
}
export function subscribe(eventClass, listener){
<?php
namespace App\Http\Middleware;
use Closure;
class GzipMiddleware
{
/**
<script>
import Icon from '../svg/Icon.svelte'
import {userIcon} from '../svg/AppIcons'
//declare icon customizable props
const props = {
color : "#4A5568",
fill : true,
size: "1.5em",
d : userIcon
<script>
export let color = "#4A5568"
export let stroke = color
export let filled = false
export let fill = filled ? color : 'none'
export let size = '1em' // default 1em match the parent element
// default heart icon
export let d = "M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"
</script>
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import {routify} from '@sveltech/routify';
import cleaner from 'rollup-plugin-cleaner';
const production = !process.env.ROLLUP_WATCH;
<script>
import SvgIcon from '../components/SvgIcon.svelte'
import {bellIcon, userIcon} from '../svg/AppIcons'
//imported only required icon names
</script>
<nav>
<a href="/notifications">
<SvgIcon d={bellIcon} fill="red"/> <!-- used bellIcon as d attribute value -->
</a>
//credit - https://github.com/refactoringui/heroicons
exports.plusIcon = "M12 4v16m8-8H4"
exports.searchIcon = "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
exports.bellIcon = "M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"
exports.userIcon= "M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
<script>
export let fill = "none"
export let d = ""
</script>
<svg class="icon" width="24" height="24" viewBox="0 0 24 24" fill={fill} xmlns="http://www.w3.org/2000/svg">
<path d={d} stroke="#4A5568" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<style>