@guestbell/react-page-plugins
Version:
Plugins we use in GuestBell for working with amazing react-page package
34 lines • 1.27 kB
JavaScript
export var Migrator = {
migrateState: function migrateState(version, state, migrations) {
var migrationResult = {
migratedState: state,
changed: false,
finalVersion: version
};
if (!migrations) {
return migrationResult;
}
if (!state) {
console.warn('State not defined when attempting to migrate.');
return migrationResult;
}
var currentDataVersion = version || 0;
while (true) {
var migration = migrations.find(function (m) {
return currentDataVersion <= m.fromVersionMax && currentDataVersion >= m.fromVersionMin && m.shouldMigrate(state, currentDataVersion);
});
migrations = migrations.filter(function (m) {
return !(currentDataVersion <= m.fromVersionMax && currentDataVersion >= m.fromVersionMin);
});
if (!migration) {
// We assume all migrations necessary for the current version of plugin to work are provided
// Therefore if we don't find any, that means we are done and state is up to date
break;
}
currentDataVersion = migration.toVersion;
migrationResult = migration.migrate(migrationResult.migratedState, currentDataVersion);
}
return migrationResult;
}
};
//# sourceMappingURL=Migrator.js.map