@@ -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 }
0 commit comments