Use callback during setState()

This commit is contained in:
Scott E. Graves
2018-10-15 17:15:25 -05:00
parent e310b0c5b6
commit 2dbb791a5f
3 changed files with 123 additions and 118 deletions

View File

@@ -164,11 +164,12 @@ class Configuration extends Component {
if (arg.data.Success) {
this.setState({
Template: arg.data.Template,
});
ipcRenderer.send(Constants.IPC_Get_Config, {
Directory: this.props.directory,
StorageType: this.props.storageType,
Version: this.props.version,
}, ()=> {
ipcRenderer.send(Constants.IPC_Get_Config, {
Directory: this.props.directory,
StorageType: this.props.storageType,
Version: this.props.version,
});
});
} else {
this.props.errorHandler(arg.data.Error, () => {
@@ -185,32 +186,32 @@ class Configuration extends Component {
if (ipcRenderer) {
this.setState({
Saving: true,
});
}, ()=> {
const changedItems = [];
for (const item of this.state.ChangedItems) {
changedItems.push({
Name: item.label,
Value: item.value,
});
}
const changedItems = [];
for (const item of this.state.ChangedItems) {
changedItems.push({
Name: item.label,
Value: item.value,
});
}
if (this.state.ChangedObjectLookup) {
for (const key of Object.keys(this.state.ChangedObjectLookup)) {
for (const item of this.state.ChangedObjectLookup[key]) {
changedItems.push({
Name: key + '.' + item.label,
Value: item.value,
});
if (this.state.ChangedObjectLookup) {
for (const key of Object.keys(this.state.ChangedObjectLookup)) {
for (const item of this.state.ChangedObjectLookup[key]) {
changedItems.push({
Name: key + '.' + item.label,
Value: item.value,
});
}
}
}
}
ipcRenderer.send(Constants.IPC_Set_Config_Values, {
Directory: this.props.directory,
Items: changedItems,
StorageType: this.props.storageType,
Version: this.props.version,
ipcRenderer.send(Constants.IPC_Set_Config_Values, {
Directory: this.props.directory,
Items: changedItems,
StorageType: this.props.storageType,
Version: this.props.version,
});
});
}
};

View File

@@ -69,28 +69,29 @@ class MountItems extends Component {
...this.state[storageType],
AllowMount: false,
};
this.setState({
[storageType]: state,
});
this.props.mountsBusy(true);
if (mount) {
ipcRenderer.send(Constants.IPC_Mount_Drive, {
Directory: this.props.directory,
Location: location,
StorageType: storageType,
Version: this.props.version,
});
} else {
ipcRenderer.send(Constants.IPC_Unmount_Drive, {
Directory: this.props.directory,
Location: location,
PID: pid,
StorageType: storageType,
Version: this.props.version,
});
}
this.setState({
[storageType]: state,
}, ()=> {
if (mount) {
ipcRenderer.send(Constants.IPC_Mount_Drive, {
Directory: this.props.directory,
Location: location,
StorageType: storageType,
Version: this.props.version,
});
} else {
ipcRenderer.send(Constants.IPC_Unmount_Drive, {
Directory: this.props.directory,
Location: location,
PID: pid,
StorageType: storageType,
Version: this.props.version,
});
}
});
}
};
@@ -111,30 +112,30 @@ class MountItems extends Component {
PID: arg.data.PIDS.Hyperspace,
};
this.props.mountsBusy(hs.Mounted || sia.Mounted);
this.setState({
Hyperspace: hs,
Sia: sia,
}, () => {
let hsLocation = arg.data.Locations.Hyperspace;
if ((hsLocation.length === 0) && (this.props.platform === 'win32')) {
hsLocation = this.props.hyperspace.MountLocation || arg.data.DriveLetters.Hyperspace[0];
}
if (hsLocation !== this.props.hyperspace.MountLocation) {
this.props.changed('Hyperspace', hsLocation);
}
let siaLocation = arg.data.Locations.Sia;
if ((siaLocation.length === 0) && (this.props.platform === 'win32')) {
siaLocation = this.props.sia.MountLocation || arg.data.DriveLetters.Sia[0];
}
if (siaLocation !== this.props.sia.MountLocation) {
this.props.changed('Sia', siaLocation);
}
this.performAutoMount();
});
this.props.mountsBusy(hs.Mounted || sia.Mounted);
let hsLocation = arg.data.Locations.Hyperspace;
if ((hsLocation.length === 0) && (this.props.platform === 'win32')) {
hsLocation = this.props.hyperspace.MountLocation || arg.data.DriveLetters.Hyperspace[0];
}
if (hsLocation !== this.props.hyperspace.MountLocation) {
this.props.changed('Hyperspace', hsLocation);
}
let siaLocation = arg.data.Locations.Sia;
if ((siaLocation.length === 0) && (this.props.platform === 'win32')) {
siaLocation = this.props.sia.MountLocation || arg.data.DriveLetters.Sia[0];
}
if (siaLocation !== this.props.sia.MountLocation) {
this.props.changed('Sia', siaLocation);
}
this.performAutoMount();
} else {
this.props.errorHandler(arg.data.Error);
}
@@ -148,9 +149,9 @@ class MountItems extends Component {
};
this.setState({
[arg.data.StorageType]: state,
}, ()=> {
this.detectMounts();
});
this.detectMounts();
};
onUnmountDriveReply = (event, arg) => {