Last active
November 8, 2024 22:10
-
-
Save markmals/242b3ac4247e5ad3c479bfedfd49280f to your computer and use it in GitHub Desktop.
Helper functions missing from Angular's Signal implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { signal, computed } from '@angular/core' | |
function writable<T>(fn: () => T) { | |
const c = computed(() => signal(fn())) | |
const w = () => c()() | |
Object.assign(w, { set: value => c().set(value) }) | |
return w | |
} | |
function derived<T>(value: T, fn: (previous: T) => T) { | |
return computed(() => (value = fn(value))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment