wrapping a generic function in typescript
i'm trying to write a wrapper to automatically handle loading state when necessary. my idea is to wrap my function definitions in this function
busyable
which then returns a function that precedes and succeeds the callback passed in by toggling busy state. something like this:
something is off (likely function parameters), and it seems like my function might be getting run twice. any help is appreciated.4 Replies
oh wait, it is actually working, though i'd love to hear of any potential improvements
Is your intended usage for this immediately following a variable declaration for busy? Otherwise this is setting a global
busy
and will run into conflicts with other things using this function.
Even if you do put it right after a busy variable, you only get one of those per lexical scope
It seems like you’re trying to kinda reinvent the promise hereits globally declared, using for render logic; the idea was primarily to use it for disabled state on buttons
yea i think im over complicating this i suppose
so you want all buttons to be disabled of any kind of (wrapped) async operation is going on?
not just disabled based on things each button controls respectively?