aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/migrator/index.js
diff options
context:
space:
mode:
authorDan Finlay <542863+danfinlay@users.noreply.github.com>2018-04-19 06:37:50 +0800
committerGitHub <noreply@github.com>2018-04-19 06:37:50 +0800
commit4544d57f2632ce5a00dc8780a7b360ab9b2657c3 (patch)
treecc7acf6302befb1e898571c800f873d670cf7cd5 /app/scripts/lib/migrator/index.js
parent6742a5b2722da7af9320f46b18e9f4b59c5666ba (diff)
parent603c1310ffc0cdb61a66f68b8240e76c2ae7cb04 (diff)
downloadtangerine-wallet-browser-4544d57f2632ce5a00dc8780a7b360ab9b2657c3.tar.gz
tangerine-wallet-browser-4544d57f2632ce5a00dc8780a7b360ab9b2657c3.tar.zst
tangerine-wallet-browser-4544d57f2632ce5a00dc8780a7b360ab9b2657c3.zip
Merge pull request #3984 from whymarrh/3941-jsdoc
Add a few 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,
}
}