# Zignal **Repository Path**: wavef/zignal ## Basic Information - **Project Name**: Zignal - **Description**: 简单的signal实现 - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-31 - **Last Updated**: 2025-01-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Zignal #### 介绍 简单的signal实现 *A simple signal implementation* ```js import { zignal, computed } from './zignal.js'; // 创建普通信号 // Create a regular signal const count = zignal(0); // 创建计算信号 // Create a computed signal const doubleCount = computed(() => count.get() * 2, [count]); // 订阅普通信号 // Subscribe to the regular signal const unsubscribeCount = count.subscribe((newValue) => { console.log(`count 变更为 ${newValue}`); // Output: count changed to ${newValue} }); // 订阅计算信号 // Subscribe to the computed signal const unsubscribeDouble = doubleCount.subscribe((newValue) => { console.log(`doubleCount 变更为 ${newValue}`); // Output: doubleCount changed to ${newValue} }); // 更新普通信号 // Update the regular signal count.set(1); // 输出 count 变更为 1, doubleCount 变更为 2 // Logs: count changed to 1, doubleCount changed to 2 // 取消订阅 // Unsubscribe unsubscribeCount(); unsubscribeDouble(); // 销毁计算信号 // Dispose of the computed signal doubleCount.dispose(); ```