Skip to content

Commit 1ee7782

Browse files
committed
#6956 core.Config cleanup
1 parent 542e84b commit 1ee7782

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/core/Config.mjs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,33 @@ class Config {
128128
/**
129129
* Subscribes a callback function to changes in this config's value.
130130
* The callback will be invoked with `(newValue, oldValue)` whenever the config changes.
131-
* @param {Object} options - An object containing the subscription details.
132-
* @param {String} options.id - A unique ID for the subscription, useful for debugging.
131+
* @param {Object} options - An object containing the subscription details.
132+
* @param {String} options.id - The ID of the subscription owner (e.g., a Neo.core.Base instance's id).
133133
* @param {Function} options.fn - The callback function.
134134
* @returns {Function} A cleanup function to unsubscribe the callback.
135135
*/
136136
subscribe({id, fn}) {
137137
if (typeof id !== 'string' || id.length === 0 || typeof fn !== 'function') {
138-
throw new Error('Config.subscribe: options must be an object with a non-empty string `id` and a function `fn`.');
138+
throw new Error([
139+
'Config.subscribe: options must be an object with a non-empty string `id` ',
140+
'(the subscription owner\'s id), and a callback function `fn`.'
141+
].join(''))
139142
}
140143

141-
if (!this.#subscribers[id]) {
142-
this.#subscribers[id] = new Set();
144+
const me = this;
145+
146+
if (!me.#subscribers[id]) {
147+
me.#subscribers[id] = new Set()
143148
}
144149

145-
this.#subscribers[id].add(fn);
150+
me.#subscribers[id].add(fn);
146151

147152
return () => {
148-
const subscriberSet = this.#subscribers[id];
153+
const subscriberSet = me.#subscribers[id];
149154
if (subscriberSet) {
150155
subscriberSet.delete(fn);
151156
if (subscriberSet.size === 0) {
152-
delete this.#subscribers[id];
157+
delete me.#subscribers[id]
153158
}
154159
}
155160
};

0 commit comments

Comments
 (0)