diff options
author | frankiebee <frankie.diamond@gmail.com> | 2018-04-20 02:29:26 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2018-04-20 02:46:15 +0800 |
commit | eeb9390de81ce6fc92247d5c499e991dce8330bd (patch) | |
tree | 400f07cb6028e6e1f8ae5328d1c5544277de837f /app/scripts/controllers/transactions/lib/tx-state-history-helper.js | |
parent | 943eea043cc40ea42ffe757a7115ccbc5585b37b (diff) | |
download | tangerine-wallet-browser-eeb9390de81ce6fc92247d5c499e991dce8330bd.tar.gz tangerine-wallet-browser-eeb9390de81ce6fc92247d5c499e991dce8330bd.tar.zst tangerine-wallet-browser-eeb9390de81ce6fc92247d5c499e991dce8330bd.zip |
meta - transactions - docs yo!
Diffstat (limited to 'app/scripts/controllers/transactions/lib/tx-state-history-helper.js')
-rw-r--r-- | app/scripts/controllers/transactions/lib/tx-state-history-helper.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/app/scripts/controllers/transactions/lib/tx-state-history-helper.js b/app/scripts/controllers/transactions/lib/tx-state-history-helper.js index 94c7b6792..7a57e3cb5 100644 --- a/app/scripts/controllers/transactions/lib/tx-state-history-helper.js +++ b/app/scripts/controllers/transactions/lib/tx-state-history-helper.js @@ -1,6 +1,6 @@ const jsonDiffer = require('fast-json-patch') const clone = require('clone') - +/** @module*/ module.exports = { generateHistoryEntry, replayHistory, @@ -8,7 +8,11 @@ module.exports = { migrateFromSnapshotsToDiffs, } - +/** + converts non-initial history entries into diffs + @param longHistory {array} + @returns {array} +*/ function migrateFromSnapshotsToDiffs (longHistory) { return ( longHistory @@ -20,6 +24,17 @@ function migrateFromSnapshotsToDiffs (longHistory) { ) } +/** + generates an array of history objects sense the previous state. + The object has the keys opp(the operation preformed), + path(the key and if a nested object then each key will be seperated with a `/`) + value + with the first entry having the note + @param previousState {object} - the previous state of the object + @param newState {object} - the update object + @param note {string} - a optional note for the state change + @reurns {array} +*/ function generateHistoryEntry (previousState, newState, note) { const entry = jsonDiffer.compare(previousState, newState) // Add a note to the first op, since it breaks if we append it to the entry @@ -27,11 +42,19 @@ function generateHistoryEntry (previousState, newState, note) { return entry } +/** + Recovers previous txMeta state obj + @return {object} +*/ function replayHistory (_shortHistory) { const shortHistory = clone(_shortHistory) return shortHistory.reduce((val, entry) => jsonDiffer.applyPatch(val, entry).newDocument) } +/** + @param txMeta {object} + @returns {object} a clone object of the txMeta with out history +*/ function snapshotFromTxMeta (txMeta) { // create txMeta snapshot for history const snapshot = clone(txMeta) |