What would trigger something like this:
router.cljc:204 Uncaught #error {:message "Unexpected compile spec type", :data {:given nil, :type nil}}
eval @ router.cljc:204
eval @ router.cljc:151
eval @ router.cljc:169
eval @ router.cljc:183
eval @ router.cljc:198
eval @ router.cljc:146
eval @ router.cljc:169
G__54585 @ router.cljc:187
channel.port1.onmessage @ nexttick.js:218
oh my
I used a (comment block) instead of #_ in a vector
That was a first
Hi all, am I correct in understanding that interceptors are meant to be synchronous? I see examples of pulling from localStorage, but I’m wanting to use the localforage
lib which is async. Should I instead be using an effect handler for any async work?
@p-himik is correct. Just to be clear if it is async state, like get a value from a server or get gps co-ordinates or just an async db, then it needs to be an effect with an on-success/on-failure etc event vectors to dispatch with the result.
@superstructor - Thank you, got it!
Yes, interceptors do their job right when the event is processed. You could make a particular interceptor async, but it's probably not worth it - it would heavily rely on re-frame internals.
You could use an effect to set values, but you can't get them back.
But why would you want to use localforage
in the fist place? The underlying localStorate
is not async, meaning that using localforage
won't give you any performance benefits and it's exactly like using localStorage
+ promises + some particular serialization library (since localforage
handles more than just strings).
You can do all that (without the promises part since you don't need async) with just localStorage
and have one dependency less and cleaner code without all the .then
.
Ah, there's this section that I missed: > includes a localStorage-backed fallback store for browsers with no IndexedDB or WebSQL support So it's not really a local storage thing. Yep, it has been asked before. It's unfeasible to use IndexedDB with re-frame exactly because it's async, and same follows for localforage.
Thank you @p-himik for the breakdown. So in general if I must use something async, I should only look at effect handlers? Maybe use something like async-flow-fx
or just write handlers and string them together?
If it's something effectful, yes. getValue
, for example, is not effectful by itself. You could put it into the app-db
right in that effect handler though.
But in the case of localStorage, I would still rather use it directly, without any wrappers that just make you write more boilerplate.
Yes I agree, thank you for bringing this up.