mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-23 07:19:50 -04:00
clean up the code a bit
This commit is contained in:
parent
2bf8fd38a4
commit
90379d331e
@ -35,7 +35,7 @@ export class MigrationVersion0to1 {
|
||||
const savedPages = this.toSavedPages(v);
|
||||
const currentCards = this.toCurrentCards(v);
|
||||
|
||||
storage.setRemote(
|
||||
storage.setRemoteData(
|
||||
settings,
|
||||
savedPages,
|
||||
{
|
||||
|
@ -100,45 +100,48 @@ export class StorageService extends SubscriberBase {
|
||||
super();
|
||||
}
|
||||
|
||||
//#region Remote
|
||||
|
||||
initRemote(user: User) {
|
||||
// do the necessary migration steps.
|
||||
this.handleMigration(user);
|
||||
|
||||
// initialize the remote store monitoring. This is where we listen for changes on the remote location.
|
||||
|
||||
this.monitorRemote<Settings>(
|
||||
this.settingsPath,
|
||||
user,
|
||||
(ro) => {
|
||||
this.settingsRemoteObject = ro;
|
||||
},
|
||||
(data) => {
|
||||
this.appService.updateSettings(data);
|
||||
}
|
||||
this.settingsRemoteObject = this.remote.object<IStorable<Settings>>(`/${this.settingsPath}/${user.uid}`);
|
||||
this.addSubscription(
|
||||
this.settingsRemoteObject
|
||||
.valueChanges() // when the value changes
|
||||
.subscribe((remoteData) => {
|
||||
if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) {
|
||||
// update the app state with remote data if it isn't null
|
||||
// console.log('Data recieved from remote store', remoteData);
|
||||
this.appService.updateSettings(remoteData);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this.monitorRemote<SavedPage[]>(
|
||||
this.savedPagesPath,
|
||||
user,
|
||||
(ro) => {
|
||||
this.savedPagesRemoteObject = ro;
|
||||
},
|
||||
(data) => {
|
||||
this.appService.updateSavedPages(data);
|
||||
}
|
||||
this.savedPagesRemoteObject = this.remote.object<IStorable<SavedPage[]>>(`/${this.savedPagesPath}/${user.uid}`);
|
||||
this.addSubscription(
|
||||
this.savedPagesRemoteObject
|
||||
.valueChanges() // when the value changes
|
||||
.subscribe((remoteData) => {
|
||||
if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) {
|
||||
// update the app state with remote data if it isn't null
|
||||
// console.log('Data recieved from remote store', remoteData);
|
||||
this.appService.updateSavedPages(remoteData);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this.monitorRemote<NoteItem[]>(
|
||||
this.noteItemsPath,
|
||||
user,
|
||||
(ro) => {
|
||||
this.noteItemsRemoteObject = ro;
|
||||
},
|
||||
(data) => {
|
||||
this.appService.updateNotes(data);
|
||||
}
|
||||
this.noteItemsRemoteObject = this.remote.object<IStorable<NoteItem[]>>(`/${this.noteItemsPath}/${user.uid}`);
|
||||
this.addSubscription(
|
||||
this.noteItemsRemoteObject
|
||||
.valueChanges() // when the value changes
|
||||
.subscribe((remoteData) => {
|
||||
if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) {
|
||||
// update the app state with remote data if it isn't null
|
||||
// console.log('Data recieved from remote store', remoteData);
|
||||
this.appService.updateNotes(remoteData);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// handle cards differently, because there is a setting that changes the behavior of how you handle
|
||||
@ -156,31 +159,6 @@ export class StorageService extends SubscriberBase {
|
||||
);
|
||||
}
|
||||
|
||||
private monitorRemote<T>(
|
||||
path: string,
|
||||
user: User,
|
||||
setRemoteObject: (remoteObject: AngularFireObject<IStorable<T>>) => void,
|
||||
action: (storable) => void
|
||||
) {
|
||||
const remoteObject = this.remote.object<IStorable<T>>(`/${path}/${user.uid}`);
|
||||
setRemoteObject(remoteObject);
|
||||
|
||||
// display settings
|
||||
this.addSubscription(
|
||||
remoteObject
|
||||
.valueChanges() // when the value changes
|
||||
.subscribe((remoteData) => {
|
||||
if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) {
|
||||
// update the app state with remote data if it isn't null
|
||||
// console.log('Data recieved from remote store', remoteData);
|
||||
action(remoteData);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Local
|
||||
|
||||
/*
|
||||
@ -330,6 +308,7 @@ export class StorageService extends SubscriberBase {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Migrations
|
||||
@ -348,7 +327,7 @@ export class StorageService extends SubscriberBase {
|
||||
});
|
||||
}
|
||||
|
||||
public setRemote(
|
||||
public setRemoteData(
|
||||
settings: IStorable<Settings>,
|
||||
savedPages: IStorable<SavedPage[]>,
|
||||
notes: IStorable<NoteItem[]>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user