mirror of
https://gitlab.com/walljm/dynamicbible.git
synced 2025-07-26 17:10:11 -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 savedPages = this.toSavedPages(v);
|
||||||
const currentCards = this.toCurrentCards(v);
|
const currentCards = this.toCurrentCards(v);
|
||||||
|
|
||||||
storage.setRemote(
|
storage.setRemoteData(
|
||||||
settings,
|
settings,
|
||||||
savedPages,
|
savedPages,
|
||||||
{
|
{
|
||||||
|
@ -100,45 +100,48 @@ export class StorageService extends SubscriberBase {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
//#region Remote
|
|
||||||
|
|
||||||
initRemote(user: User) {
|
initRemote(user: User) {
|
||||||
// do the necessary migration steps.
|
// do the necessary migration steps.
|
||||||
this.handleMigration(user);
|
this.handleMigration(user);
|
||||||
|
|
||||||
// initialize the remote store monitoring. This is where we listen for changes on the remote location.
|
// initialize the remote store monitoring. This is where we listen for changes on the remote location.
|
||||||
|
this.settingsRemoteObject = this.remote.object<IStorable<Settings>>(`/${this.settingsPath}/${user.uid}`);
|
||||||
this.monitorRemote<Settings>(
|
this.addSubscription(
|
||||||
this.settingsPath,
|
this.settingsRemoteObject
|
||||||
user,
|
.valueChanges() // when the value changes
|
||||||
(ro) => {
|
.subscribe((remoteData) => {
|
||||||
this.settingsRemoteObject = ro;
|
if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) {
|
||||||
},
|
// update the app state with remote data if it isn't null
|
||||||
(data) => {
|
// console.log('Data recieved from remote store', remoteData);
|
||||||
this.appService.updateSettings(data);
|
this.appService.updateSettings(remoteData);
|
||||||
}
|
}
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.monitorRemote<SavedPage[]>(
|
this.savedPagesRemoteObject = this.remote.object<IStorable<SavedPage[]>>(`/${this.savedPagesPath}/${user.uid}`);
|
||||||
this.savedPagesPath,
|
this.addSubscription(
|
||||||
user,
|
this.savedPagesRemoteObject
|
||||||
(ro) => {
|
.valueChanges() // when the value changes
|
||||||
this.savedPagesRemoteObject = ro;
|
.subscribe((remoteData) => {
|
||||||
},
|
if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) {
|
||||||
(data) => {
|
// update the app state with remote data if it isn't null
|
||||||
this.appService.updateSavedPages(data);
|
// console.log('Data recieved from remote store', remoteData);
|
||||||
}
|
this.appService.updateSavedPages(remoteData);
|
||||||
|
}
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this.monitorRemote<NoteItem[]>(
|
this.noteItemsRemoteObject = this.remote.object<IStorable<NoteItem[]>>(`/${this.noteItemsPath}/${user.uid}`);
|
||||||
this.noteItemsPath,
|
this.addSubscription(
|
||||||
user,
|
this.noteItemsRemoteObject
|
||||||
(ro) => {
|
.valueChanges() // when the value changes
|
||||||
this.noteItemsRemoteObject = ro;
|
.subscribe((remoteData) => {
|
||||||
},
|
if (!isNullOrUndefined(remoteData) && !isNullOrUndefined(remoteData.value)) {
|
||||||
(data) => {
|
// update the app state with remote data if it isn't null
|
||||||
this.appService.updateNotes(data);
|
// 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
|
// 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
|
//#region Local
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -330,6 +308,7 @@ export class StorageService extends SubscriberBase {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region Migrations
|
//#region Migrations
|
||||||
@ -348,7 +327,7 @@ export class StorageService extends SubscriberBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public setRemote(
|
public setRemoteData(
|
||||||
settings: IStorable<Settings>,
|
settings: IStorable<Settings>,
|
||||||
savedPages: IStorable<SavedPage[]>,
|
savedPages: IStorable<SavedPage[]>,
|
||||||
notes: IStorable<NoteItem[]>,
|
notes: IStorable<NoteItem[]>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user