Skip to content

Commit 95223f6

Browse files
committed
fix(ckui): update version to 2.4.6 and enhance subscribe method to execute callback immediately
1 parent 13e771a commit 95223f6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

libs/CKUI.lib.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name CKUI
33
// @namespace ckylin-script-lib-ckui
4-
// @version 2.4.5
4+
// @version 2.4.6
55
// @description A modern, dependency-free UI library for Tampermonkey scripts
66
// @match http://*
77
// @match https://*
@@ -85,8 +85,18 @@ if (typeof unsafeWindow === 'undefined' || !unsafeWindow) {
8585
}
8686
}
8787

88-
subscribe(callback) {
88+
subscribe(callback, immediate = true) {
8989
this._subscribers.push(callback);
90+
91+
// 立即执行一次回调以同步初始值
92+
if (immediate) {
93+
try {
94+
callback(this._value);
95+
} catch (e) {
96+
console.error('[CKUI] Reactive callback error:', e);
97+
}
98+
}
99+
90100
return () => {
91101
this._subscribers = this._subscribers.filter(cb => cb !== callback);
92102
};

0 commit comments

Comments
 (0)