Skip to content

Commit

Permalink
feature/settings — Refactor settings service.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandat committed Feb 29, 2016
1 parent 221a07a commit 517fd77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/app.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
}
}

function applySettings(settingService, $ionicConfig){
!settingService.settings.enableAnimations && $ionicConfig.views.transition('none');
function applySettings(settingService){
settingService.apply();
}

function boot($state, $cordovaSplashscreen, $timeout, ImgCache, $rootScope, $log) {
Expand Down
2 changes: 1 addition & 1 deletion app/setting/setting-list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/////////////

function activate() {
$scope.$watchCollection('vm.settings', settingService.update);
$scope.$watchCollection('vm.settings', settingService.applyDiffAndPersist);
}

function clearCache() {
Expand Down
23 changes: 17 additions & 6 deletions app/setting/setting.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@

var service = {
settings: _.defaults(localStorageService.get('settings'), defaults),
update: update,
applyDiffAndPersist: applyDiffAndPersist,
apply: apply,
persist: persist,
clearCache: clearCache
};

return service;

////////////

function update(){
var settings = service.settings;

function applyDiffAndPersist(newSettings, oldSettings){
// enableAnimations property
settings.enableAnimations ? enableAnimations() : disableAnimations();
newSettings.enableAnimations !== oldSettings.enableAnimations && processEnableAnimations();
persist();
}

function persist(){
// Persist in local storage
localStorageService.set('settings', settings);
localStorageService.set('settings', service.settings);
$log.info('Settings persisted');
}

function apply(){
processEnableAnimations();
}

function processEnableAnimations(){
service.settings.enableAnimations ? enableAnimations() : disableAnimations();
}

function clearCache() {
return $q(function (resolve, reject) {

Expand Down

0 comments on commit 517fd77

Please sign in to comment.