Skip to content

Commit 517fd77

Browse files
committed
feature/settings — Refactor settings service.
1 parent 221a07a commit 517fd77

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

app/app.run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
}
139139
}
140140

141-
function applySettings(settingService, $ionicConfig){
142-
!settingService.settings.enableAnimations && $ionicConfig.views.transition('none');
141+
function applySettings(settingService){
142+
settingService.apply();
143143
}
144144

145145
function boot($state, $cordovaSplashscreen, $timeout, ImgCache, $rootScope, $log) {

app/setting/setting-list.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/////////////
1818

1919
function activate() {
20-
$scope.$watchCollection('vm.settings', settingService.update);
20+
$scope.$watchCollection('vm.settings', settingService.applyDiffAndPersist);
2121
}
2222

2323
function clearCache() {

app/setting/setting.factory.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,36 @@
1313

1414
var service = {
1515
settings: _.defaults(localStorageService.get('settings'), defaults),
16-
update: update,
16+
applyDiffAndPersist: applyDiffAndPersist,
17+
apply: apply,
18+
persist: persist,
1719
clearCache: clearCache
1820
};
1921

2022
return service;
2123

2224
////////////
2325

24-
function update(){
25-
var settings = service.settings;
26-
26+
function applyDiffAndPersist(newSettings, oldSettings){
2727
// enableAnimations property
28-
settings.enableAnimations ? enableAnimations() : disableAnimations();
28+
newSettings.enableAnimations !== oldSettings.enableAnimations && processEnableAnimations();
29+
persist();
30+
}
2931

32+
function persist(){
3033
// Persist in local storage
31-
localStorageService.set('settings', settings);
34+
localStorageService.set('settings', service.settings);
3235
$log.info('Settings persisted');
3336
}
3437

38+
function apply(){
39+
processEnableAnimations();
40+
}
41+
42+
function processEnableAnimations(){
43+
service.settings.enableAnimations ? enableAnimations() : disableAnimations();
44+
}
45+
3546
function clearCache() {
3647
return $q(function (resolve, reject) {
3748

0 commit comments

Comments
 (0)