Skip to content

Commit 071b9ef

Browse files
committed
cleanup debugging log calls
1 parent 87179fe commit 071b9ef

File tree

3 files changed

+6
-35
lines changed

3 files changed

+6
-35
lines changed

src/async-stores/index.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ export const asyncWritable = <S extends Stores, T>(
7272
let thisStore: Writable<T>;
7373

7474
flagStoreCreated();
75-
const { reloadable, initial, debug, rebounceDelay } = options;
76-
77-
const debuggy = debug ? (...args) => console.log(debug, ...args) : undefined;
75+
const { reloadable, initial, rebounceDelay } = options;
7876

7977
const rebouncedSelfLoad = rebounce(selfLoadFunction, rebounceDelay);
8078

@@ -91,16 +89,13 @@ export const asyncWritable = <S extends Stores, T>(
9189
let resolveCurrentLoad: (value: T | PromiseLike<T> | Error) => void;
9290

9391
const setCurrentLoadPromise = () => {
94-
debuggy?.('setCurrentLoadPromise -> new load promise generated');
9592
currentLoadPromise = new Promise((resolve) => {
9693
resolveCurrentLoad = resolve;
9794
});
9895
};
9996

10097
const getLoadedValueOrThrow = async (callback?: () => void) => {
101-
debuggy?.('getLoadedValue -> starting await current load');
10298
const result = await currentLoadPromise;
103-
debuggy?.('getLoadedValue -> got loaded result', result);
10499
callback?.();
105100
if (result instanceof Error) {
106101
throw result;
@@ -118,16 +113,13 @@ export const asyncWritable = <S extends Stores, T>(
118113
try {
119114
// parentValues
120115
const finalValue = (await rebouncedSelfLoad(parentValues)) as T;
121-
debuggy?.('setting value');
122116
thisStore.set(finalValue);
123117

124118
if (!get(loadState).isWriting) {
125-
debuggy?.('setting LOADED');
126119
setState('LOADED');
127120
}
128121
resolveCurrentLoad(finalValue);
129122
} catch (error) {
130-
debuggy?.('caught error', error);
131123
if (error.name === 'AbortError') {
132124
if (thisLoadTracker === mostRecentLoadTracker) {
133125
// Normally when a load is aborted we want to leave the state as is.
@@ -139,7 +131,7 @@ export const asyncWritable = <S extends Stores, T>(
139131
} else {
140132
logError(error);
141133
setState('ERROR');
142-
debuggy?.('resolving current load with error', error);
134+
143135
// Resolve with an Error rather than rejecting so that unhandled rejections
144136
// are not created by the store's internal processes. These errors are
145137
// converted back to promise rejections via the load or reload functions,
@@ -155,16 +147,13 @@ export const asyncWritable = <S extends Stores, T>(
155147

156148
// called when store receives its first subscriber
157149
const onFirstSubscription: StartStopNotifier<T> = () => {
158-
debuggy?.('onFirstSubscription');
159150
setCurrentLoadPromise();
160151
parentValues = getAll(stores);
161152
setState('LOADING');
162153

163154
const initialLoad = async () => {
164-
debuggy?.('initial load called');
165155
try {
166156
parentValues = await loadAll(stores);
167-
debuggy?.('setting ready');
168157
ready = true;
169158
changeReceived = false;
170159
selfLoadThenSet();
@@ -181,7 +170,6 @@ export const asyncWritable = <S extends Stores, T>(
181170
if (ready) {
182171
if (get(loadState).isSettled) {
183172
setCurrentLoadPromise();
184-
debuggy?.('setting RELOADING');
185173
setState('RELOADING');
186174
}
187175
ready = false;
@@ -197,17 +185,13 @@ export const asyncWritable = <S extends Stores, T>(
197185
);
198186

199187
cleanupSubscriptions = () => {
200-
debuggy?.('cleaning up subscriptions');
201188
parentUnsubscribers.map((unsubscriber) => unsubscriber());
202189
ready = false;
203190
changeReceived = false;
204191
};
205192

206193
// called on losing last subscriber
207-
return () => {
208-
debuggy?.('stopping store');
209-
cleanupSubscriptions();
210-
};
194+
return cleanupSubscriptions;
211195
};
212196

213197
thisStore = writable(initial, onFirstSubscription);
@@ -242,7 +226,6 @@ export const asyncWritable = <S extends Stores, T>(
242226
}
243227
} catch (error) {
244228
logError(error);
245-
debuggy?.('setting ERROR');
246229
setState('ERROR');
247230
resolveCurrentLoad(newValue);
248231
throw error;
@@ -270,27 +253,22 @@ export const asyncWritable = <S extends Stores, T>(
270253
ready = false;
271254
changeReceived = false;
272255
if (get(loadState).isSettled) {
273-
debuggy?.('new load promise');
274256
setCurrentLoadPromise();
275257
}
276-
debuggy?.('setting RELOADING from reload');
277258
const wasErrored = get(loadState).isError;
278259
setState('RELOADING');
279260

280261
const visitMap = visitedMap ?? new WeakMap();
281262
try {
282263
parentValues = await reloadAll(stores, visitMap);
283-
debuggy?.('parentValues', parentValues);
284264
ready = true;
285-
debuggy?.(changeReceived, reloadable, wasErrored);
286265
if (changeReceived || reloadable || wasErrored) {
287266
selfLoadThenSet();
288267
} else {
289268
resolveCurrentLoad(get(thisStore));
290269
setState('LOADED');
291270
}
292271
} catch (error) {
293-
debuggy?.('caught error during reload');
294272
setState('ERROR');
295273
resolveCurrentLoad(error);
296274
}

src/async-stores/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ export type WritableLoadable<T> = AsyncLoadable<T> & AsyncWritable<T>;
4242
export interface AsyncStoreOptions<T> {
4343
reloadable?: true;
4444
trackState?: true;
45-
debug?: string;
4645
initial?: T;
4746
rebounceDelay?: number;
4847
}

test/async-stores/index.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99
derived,
1010
readable,
1111
writable,
12-
isReloadable,
13-
rebounce,
1412
safeLoad,
1513
} from '../../src';
1614

@@ -398,15 +396,14 @@ describe('asyncWritable', () => {
398396

399397
const load = () => {
400398
const valueToReturn = getFinalValue();
401-
console.log('valueToReturn', valueToReturn);
399+
402400
return new Promise<string>((resolve) =>
403401
setTimeout(() => resolve(valueToReturn), 100)
404402
);
405403
};
406404

407405
const myLoadable = asyncReadable('initial', load, {
408406
reloadable: true,
409-
debug: 'my thing:',
410407
});
411408

412409
expect(myLoadable.load()).resolves.toBe('second');
@@ -534,9 +531,7 @@ describe('asyncWritable', () => {
534531
setTimeout(() => resolve(valueA + valueB), 100)
535532
)
536533
);
537-
const myLoadable = asyncDerived([parentA, parentB], load, {
538-
debug: 'myLoadable',
539-
});
534+
const myLoadable = asyncDerived([parentA, parentB], load);
540535
myLoadable.subscribe(vi.fn());
541536

542537
let result = await myLoadable.load();
@@ -1263,7 +1258,7 @@ describe('trackState', () => {
12631258
const { store: myStore, state: myState } = asyncReadable(
12641259
'initial',
12651260
load,
1266-
{ trackState: true, reloadable: true, debug: 'thing' }
1261+
{ trackState: true, reloadable: true }
12671262
);
12681263

12691264
myStore.subscribe(vitest.fn());
@@ -1286,7 +1281,6 @@ describe('trackState', () => {
12861281
.mockRejectedValueOnce('failure');
12871282
const myParent = asyncReadable('initial', parentLoad, {
12881283
reloadable: true,
1289-
debug: 'parent:',
12901284
});
12911285
const { store: myStore, state: myState } = asyncDerived(
12921286
myParent,

0 commit comments

Comments
 (0)