revconf
v1.0.0
Published
Revisioned configuration able to withstand major version upgrades.
Downloads
3
Readme
revconf
Revisioned configuration able to withstand major version upgrades.
Installation
You can install the plugin using NPM or bower depending on your build environment. To install with NPM, type:
npm install --save revconf
To install with Bower, type:
bower install revconf
Usage Example
This example shows how to use revconf
in your browser with one converter which enables users of older versions of your application to keep as much of their settings as possible.
To create a real scenario, first write an old configuration to your local storage:
localStorage.setItem("my-app-config", JSON.stringify({
revisions: [
{
revision: 0,
data: {
view: "table",
showAds: false,
enableNewFeatures: true,
oldSetting: "whatever"
}
}
]
}));
Then, use revconf
to convert the old configuration
into the new revision:
var defaultOptions = {
view: 'table',
showAds: true,
enableNewFeatures: false
};
var config = revconf("my-app-config")
.accessor(revconf.storageAccessor)
.converter({
from: 0, to: 1,
convert: function(oldConfig) {
return {
view: oldConfig.view,
showAds: oldConfig.showAds,
enableNewFeatures: false
};
}
})
.revision(1);
var obj = config();
console.info(obj);
if (typeof obj === "undefined") {
obj = config(defaultOptions);
}
console.info(obj);
revconf
stores the new revision alongside the old one in the local storage
to prevent any possible data loss.
Copyright
Copyright (c) 2016 Vincent Wochnik.
License: MIT