Is there a reason you’re splitting all these things up? I would just do this:
export interface Preferences {
playContinuously: boolean;
keepMediaPlaying: boolean;
playWhileHidden: boolean;
}
export class PreferenceService {
preferences: Promise<Preferences>;
constructor(private _storage: Storage) {
this.preferences = _storage.ready().then(() => _storage.get('preferences'));
}
setPreferences(prefs: Preferences): Promise<void> {
return this._storage.set('preferences', prefs).then(() => {
this.preferences = Promise.resolve(prefs);
});
}
}
export class SettingsPage {
preferences: Preferences;
constructor(private _prefService: PreferenceService) {
_prefService.preferences.then(prefs => this.preferences = prefs);
}
save(): void {
this._prefService.setPreferences(this.preferences);
}
}