aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/migrator/index.js
diff options
context:
space:
mode:
authorWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-04-16 23:29:43 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2018-04-19 04:30:22 +0800
commit603c1310ffc0cdb61a66f68b8240e76c2ae7cb04 (patch)
treee555cd0a7d6269adc636d14ee3650aac133fdc77 /app/scripts/lib/migrator/index.js
parent061975cd4a92dfcff7c98c2ab34290b8680c5545 (diff)
downloadtangerine-wallet-browser-603c1310ffc0cdb61a66f68b8240e76c2ae7cb04.tar.gz
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/index.js')
-rw-r--r--app/scripts/lib/migrator/index.js35
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,
}
}