Skip to content

Instantly share code, notes, and snippets.

View calebporzio's full-sized avatar

Caleb Porzio calebporzio

View GitHub Profile
export function detangle() {
let blocked = false
return callback => (...args) => {
if (blocked) return
blocked = true
callback(...args)

It's time to swap out these placeholders on the new Livewire landing page. Show some love!

(Please reply with a brief testimonial, name, and twitter handle)

image

import { reactive } from '@vue/reactivity'
function switchboard(value) {
let lookup = {}
let current
let get = () => current
let set = (newValue) => {
<?php
function memoize($target) {
static $memo = new WeakMap;
return new class ($target, $memo) {
function __construct(
protected $target,
protected &$memo,
) {}

Help me solve morphdom woes in Livewire

Blade "@if" statements can sometimes cause problems in Livewire.

I can eliminate those problems if I can inject markers around those conditional block like so:

@if (...)
    <div>foo</div>
@endif
<html>
<script src="/basic/canvas.js"></script>
<script src="/basic/ml.js"></script>
<div style="border: 1px solid black; width: 100px; height: 100px;">
<canvas width="200" height="200" id="points" style="position: absolute; width: 100px; height: 100px"></canvas>
<canvas width="200" height="200" id="line" style="position: absolute; width: 100px; height: 100px"></canvas>
</div>
<script>
<script data-turbo-eval="false">
document.addEventListener('turbo:before-render', () => {
let permanents = document.querySelectorAll('[data-turbo-permanent]')
let undos = Array.from(permanents).map(el => {
el._x_ignore = true
return () => {
delete el._x_ignore
}
function benchmark(times, callbacks) {
let result = {}
Object.entries(callbacks).forEach(([key, value]) => {
let thing = {}
let start = performance.now()
for (let index = 0; index < times; index++) {
value()
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tailwindcss/ui@latest/dist/tailwind-ui.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/tailwind.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>