forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import _ from 'underscore'; | ||
import Onyx from 'react-native-onyx'; | ||
import * as Request from './Request'; | ||
import * as SequentialQueue from './Network/SequentialQueue'; | ||
import {version} from '../../package.json'; | ||
|
||
function write(command, apiCommandParameters = {}, onyxData = {}) { | ||
// Optimistically update Onyx | ||
if (onyxData.optimisticData) { | ||
Onyx.update(onyxData.optimisticData); | ||
} | ||
|
||
// Assemble the data we'll send to the API | ||
const data = { | ||
...apiCommandParameters, | ||
appversion: version, | ||
}; | ||
|
||
// Assemble all the request data we'll be storing in the queue | ||
const request = { | ||
command, | ||
data, | ||
..._.omit(onyxData, 'optimisticData'), | ||
}; | ||
|
||
// Write commands can be saved and retried, so push it to the SequentialQueue | ||
SequentialQueue.push(request); | ||
} | ||
|
||
function makeRequestWithSideEffects(command, apiCommandParameters = {}, onyxData = {}) { | ||
// Optimistically update Onyx | ||
if (onyxData.optimisticData) { | ||
Onyx.update(onyxData.optimisticData); | ||
} | ||
|
||
// Assemble the data we'll send to the API | ||
const data = { | ||
...apiCommandParameters, | ||
appversion: version, | ||
}; | ||
|
||
// Assemble all the request data we'll be storing | ||
const request = { | ||
command, | ||
data, | ||
..._.omit(onyxData, 'optimisticData'), | ||
}; | ||
|
||
// Return a promise containing the response from HTTPS | ||
return Request.processWithMiddleware(request); | ||
} | ||
|
||
function read(command, apiCommandParameters, onyxData) { | ||
makeRequestWithSideEffects(command, apiCommandParameters, onyxData); | ||
} | ||
|
||
export { | ||
write, | ||
makeRequestWithSideEffects, | ||
read, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters