diff --git a/lib/Onyx.js b/lib/Onyx.js index 014e1565..82324d50 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -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); } diff --git a/lib/withOnyx.js b/lib/withOnyx.js index d0c1fb8e..123fc4ad 100644 --- a/lib/withOnyx.js +++ b/lib/withOnyx.js @@ -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}. @@ -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; } /**