Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stale closure #54

Open
6ase opened this issue Apr 27, 2024 · 2 comments
Open

stale closure #54

6ase opened this issue Apr 27, 2024 · 2 comments

Comments

@6ase
Copy link

6ase commented Apr 27, 2024

It seems there is a problem inside of component with "stale closure". I`am use the function to provide to onComplete:

const onSlidingComplete = (newValue: number) =>  {
      if (intervalId.current) clearInterval(intervalId.current);
      const [ instance, value ] = [DEVICE_COMMANDS_INSTANCE.TEMP_SP, newValue] 
      const command = constructorService.commandModify(instance, value, device.deviceType)
      console.log(device.state?.fan_speed)
      deviceService.sendCommandAndUpdateState(
        { state: { ...device.state!, temp_sp: newValue}, command },localDevice, dispatch)
      intervalId.current = deviceService.stateUpdateInterval(device._id,localDevice, dispatch , 8000)
}

"device" - object i am getting from the props or from selector
const device = useSelector(getDeviceInfo(id), _.isEqual)
The problem is: when i call onSlidingComplete - function, the device.state has an old state, even, i a checked by console.log(device.state) in the compopent and device.state in the function on onSlidingComplete - there are different values.

The problem is, that i change state of temperature in CircleSlider, trying to update main state

 { state: { ...device.state!, temp_sp: newValue}

but if change in another component, for example device.state.fan_speed - device.state inside of onSlidingComplete didnt know about that..

If i use some standard sliders from react-native - all work fine.

@ravi-roxiler
Copy link

ravi-roxiler commented Jun 10, 2024

@6ase did you found any solution around it?

@6ase
Copy link
Author

6ase commented Jun 10, 2024

@6ase did you found any solution around it?

I changed my redux actions to update only the one of parametrs. So fo each command - i create function that is not mutate other values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants