Skip to content

Instantly share code, notes, and snippets.

import 'dart:js_interop';
import 'package:web/web.dart';
void onMessage(Event event) {
if (event is MessageEvent) {
print('Worker received message: ${event.data}');
}
}
void postMessage(
import { computed, signal } from "@preact/signals-core";
import { html } from "@lit-labs/preact-signals";
import { LitTemplateMixin } from "./mixins.js";
import { mix } from "./mixwith.js";
import { styleMap } from "lit/directives/style-map.js";
class Example extends mix(HTMLElement).with(LitTemplateMixin) {
tags = signal<string[]>([
"Docker",
"Kubernetes",
import { computed } from "@preact/signals-core";
import { css } from "lit";
import { html } from "@lit-labs/preact-signals";
import { WithShadowRoot } from "./element-utils.js";
class Counter extends WithShadowRoot(HTMLElement) {
count = this.attr("count", "0");
countInt = computed(() => parseInt(this.count.value));
private increment() {
import {
ReadonlySignal,
Signal,
computed,
effect,
signal,
} from "@preact/signals-core";
import { CSSResult, render, TemplateResult, unsafeCSS, html } from "lit";
export type Style = string | CSSResult | CSSStyleSheet;
import { ReadonlySignal, computed, effect, signal } from "@preact/signals-core";
export class AsyncState<T> {
constructor() {}
get value(): T | null {
return null;
}
get requireValue(): T {
@rodydavis
rodydavis / counter.ts
Last active January 16, 2025 06:46
Lit + Signals
import { computed } from "@preact/signals-core";
import { css } from "lit";
import { html } from "@lit-labs/preact-signals";
import { WithShadowRoot, WithLitTemplate } from "./utils.js";
class Counter extends WithShadowRoot(HTMLElement) {
count = this.attr("count", "0");
countInt = computed(() => parseInt(this.count.value));
private increment() {
@rodydavis
rodydavis / counter.ts
Last active January 15, 2025 17:12
Signals + Web Components
import { computed, signal } from "@preact/signals-core";
import { type SignalsTemplate, render } from "./signals-template";
import { SignalsWebComponent } from "./signals-web-component";
const tagName = "x-counter";
class Counter extends SignalsWebComponent {
counter = signal(0);
counterStr = computed(() => this.counter.value.toString());
@rodydavis
rodydavis / main.dart
Last active December 18, 2024 19:31
Signals with functional widget
// ignore_for_file: non_constant_identifier_names
import 'package:flutter/material.dart';
import 'package:signals/signals_flutter.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Counter((
counter: signal(0),
@rodydavis
rodydavis / main.dart
Created December 18, 2024 08:20
Signals functional widgets
// ignore_for_file: non_constant_identifier_names
import 'package:flutter/material.dart';
import 'package:signals/signals_flutter.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: Counter(),
));
@rodydavis
rodydavis / main.dart
Last active December 18, 2024 18:03
Mix FLutter example
import 'package:flutter/material.dart';
import 'package:signals/signals_flutter.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:mix/mix.dart';
const _colors = ColorTokens();
const _fonts = TextStyleTokens();
final seedColor = signal(const Color(0xFF7326E0));