javascript - What is the recommended way to handle changes in local web storage from upstream? -
the question general approach. me, try present problem using angularjs ngstorage.
let's have saved in local storage:
$scope.$storage = $localstorage; $scope.$storage.food = { type: 'candy', eaten: false }
with way, i've saved in local storage. next time user visit page, know if he/she has eaten candy. however, in future, change app , change structure of food.
so how should update this? 2 things must took care of are:
- notify client of new structure storing.
- integrate change old storage.
my approach using version field indicate changes, , upon seeing that, reset clients storage.
this process called "data migration" (i.e. upgrading data structure application evolves). it's well-known problem database world (and before config/preferences files).
the usual approach add version in header of data structure. means header same (or changes in backwards-compatible ways) while payload (the actual data) can change as needs.
a simple solution checks version , uses defaults when version doesn't match. more elaborate schemes contain migration code can upgrade data structure version n
n+1
. control code apply migration steps necessary upgrade data structures latest version.
Comments
Post a Comment