Skip to content

Commit

Permalink
rename setInitialState
Browse files Browse the repository at this point in the history
  • Loading branch information
marcaaron committed Aug 17, 2021
1 parent 131ef8d commit 722492b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/Onyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function keyChanged(key, data, hasNewValue = true) {
*/
function sendDataToConnection(config, val, key) {
if (config.withOnyxInstance) {
config.withOnyxInstance.setInitialState(config.statePropertyName, val);
config.withOnyxInstance.setWithOnyxState(config.statePropertyName, val);
} else if (_.isFunction(config.callback)) {
config.callback(val, key);
}
Expand Down
22 changes: 11 additions & 11 deletions lib/withOnyx.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function (mapOnyxToState) {
constructor(props) {
super(props);

this.setInitialState = this.setInitialState.bind(this);
this.setWithOnyxState = this.setWithOnyxState.bind(this);

// This stores all the Onyx connection IDs to be used when the component unmounts so everything can be
// disconnected. It is a key value store with the format {[mapping.key]: connectionID}.
Expand Down Expand Up @@ -86,21 +86,21 @@ export default function (mapOnyxToState) {
* @param {String} statePropertyName
* @param {*} val
*/
setInitialState(statePropertyName, val) {
if (this.state.loading) {
this.tempState[statePropertyName] = val;
setWithOnyxState(statePropertyName, val) {
if (!this.state.loading) {
this.setState({[statePropertyName]: val});
return;
}

// All state keys should exist and at least have a value of null
if (_.some(requiredKeysForInit, key => _.isUndefined(this.tempState[key]))) {
return;
}
this.tempState[statePropertyName] = val;

this.setState({...this.tempState, loading: false});
delete this.tempState;
// All state keys should exist and at least have a value of null
if (_.some(requiredKeysForInit, key => _.isUndefined(this.tempState[key]))) {
return;
}

this.setState({[statePropertyName]: val});
this.setState({...this.tempState, loading: false});
delete this.tempState;
}

/**
Expand Down

0 comments on commit 722492b

Please sign in to comment.