Fork me on GitHub
#fulcro
<
2024-04-20
>
Rei08:04:30

@tony.kay Hey Tony. If you recall, we talked about custom remote a few weeks ago. For context, I wanted to make a custom remote that interacts with other parts of the mobile app. Everything seems to be working fine, but I'm seeing some unexpected behaviour at the moment. I'm making 2 load! calls with the custom remote, each successfully runs and returns the correct data, but it seems that when the load call returns, it's modifying the old state instead of the current state.

initial states when loads are called
{:raw-video-url nil,
 :ui/is-playing? false,
 :ui/is-buffering? true, 
 :ui/first-load? false}

some other mutations happened when the load A and B is still running
{:raw-video-url "",
 :ui/is-playing? false,
 :ui/is-buffering? true, 
 :ui/first-load? false, 
 :service-type :youtube}

load A finishes:
{:ui/is-playing? false,
 :ui/is-buffering? true,
 :ui/first-load? false,
 :stream-info {...}}

load B finishes:
{:ui/is-playing? false,
 :ui/is-buffering? true,
 :ui/first-load? false,
 :comments-info {...}}
Any insights into why this may be happening?

2
Rei09:04:25

I think this is because I'm making 2 loads that target the same component, but at this point i have no idea

tony.kay17:04:57

So I would need to know some more things. Typically when you see things that look like they're in the wrong order it means you're nesting swaps somehow, which you shouldn't even be dealing with at the remote level. Are you loading from two different remotes and targeting the same thing? If it is a single remote, then fulcro automatically puts a queue in place so that only one thing happens at a time.

tony.kay17:04:22

Is it possible you're calling the result handler more than once?

Rei08:04:50

@tony.kay Yeah I was doing 2 loads (one after another immediately) that targeted the same thing. I've fixed this by making the remote able to handle 2 separate ops within a single load, so all is well now. 2 internal loads (interacting with the other stuff) return 2 promises, which I just join them and do a single result-handler at the end 😄