diff options
author | Whymarrh Whitby <whymarrh.whitby@gmail.com> | 2018-04-16 23:29:43 +0800 |
---|---|---|
committer | Whymarrh Whitby <whymarrh.whitby@gmail.com> | 2018-04-19 04:30:22 +0800 |
commit | 603c1310ffc0cdb61a66f68b8240e76c2ae7cb04 (patch) | |
tree | e555cd0a7d6269adc636d14ee3650aac133fdc77 /app/scripts/lib/migrator | |
parent | 061975cd4a92dfcff7c98c2ab34290b8680c5545 (diff) | |
download | tangerine-wallet-browser-603c1310ffc0cdb61a66f68b8240e76c2ae7cb04.tar tangerine-wallet-browser-603c1310ffc0cdb61a66f68b8240e76c2ae7cb04.tar.gz tangerine-wallet-browser-603c1310ffc0cdb61a66f68b8240e76c2ae7cb04.tar.bz2 tangerine-wallet-browser-603c1310ffc0cdb61a66f68b8240e76c2ae7cb04.tar.lz tangerine-wallet-browser-603c1310ffc0cdb61a66f68b8240e76c2ae7cb04.tar.xz tangerine-wallet-browser-603c1310ffc0cdb61a66f68b8240e76c2ae7cb04.tar.zst tangerine-wallet-browser-603c1310ffc0cdb61a66f68b8240e76c2ae7cb04.zip |
Add a few missing docblocks to background files
Diffstat (limited to 'app/scripts/lib/migrator')
-rw-r--r-- | app/scripts/lib/migrator/index.js | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js index 85c2717ea..345ca8001 100644 --- a/app/scripts/lib/migrator/index.js +++ b/app/scripts/lib/migrator/index.js @@ -1,7 +1,23 @@ const EventEmitter = require('events') +/** + * @typedef {object} Migration + * @property {number} version - The migration version + * @property {Function} migrate - Returns a promise of the migrated data + */ + +/** + * @typedef {object} MigratorOptions + * @property {Array<Migration>} [migrations] - The list of migrations to apply + * @property {number} [defaultVersion] - The version to use in the initial state + */ + class Migrator extends EventEmitter { + /** + * @constructor + * @param {MigratorOptions} opts + */ constructor (opts = {}) { super() const migrations = opts.migrations || [] @@ -42,19 +58,30 @@ class Migrator extends EventEmitter { return versionedData - // migration is "pending" if it has a higher - // version number than currentVersion + /** + * Returns whether or not the migration is pending + * + * A migration is considered "pending" if it has a higher + * version number than the current version. + * @param {Migration} migration + * @returns {boolean} + */ function migrationIsPending (migration) { return migration.version > versionedData.meta.version } } - generateInitialState (initState) { + /** + * Returns the initial state for the migrator + * @param {object} [data] - The data for the initial state + * @returns {{meta: {version: number}, data: any}} + */ + generateInitialState (data) { return { meta: { version: this.defaultVersion, }, - data: initState, + data, } } |