src/lib/services/sz-prefs.service.ts
Provides a composite UI Event BUS / Preferences datastore. every time a pref in the datastore is changed publishes a "prefsChanged" rxjs BehaviorSubject that can be subscribed and responded to.
when a component UI event happens(ie: user collapses all nodes in an entity detail section) the component updates the corresponding value through this service.
representational state is published and responded to through this class. it is up to the end consumer what to do with this data. it is not stored anywhere other than in memory by default. the third example shows how to load from localstorage.
Example :constructor(private prefs: SzPrefsService) {
this.prefs.prefsChanged.subscribe((prefs: SzSdkPrefsModel) => { console.log('prefs changed!', prefs); })
}
constructor(private prefs: SzPrefsService) {
currentState = this.prefs.toJSONObject();
}
constructor(private prefs: SzPrefsService, Inject(LOCAL_STORAGE) private storage: StorageService) {
// get from ls
let _ls = this.storage.get("name_of_local_storage_store");
this.prefs.fromJSONString( _ls );
// store in ls
this.prefs.prefsChanged.subscribe((prefs: SzSdkPrefsModel) => { this.storage.set("name_of_local_storage_store", prefs); })
}
constructor(private prefs: SzPrefsService) {
// set graph to collapsed by default
this.prefs.entityDetail.graphSectionCollapsed = true;
}
Properties |
|
Methods |
|
constructor()
|
Public fromJSONObject | ||||||
fromJSONObject(value: SzSdkPrefsModel)
|
||||||
populate values from JSON. bulk import basically.
Parameters :
Returns :
void
|
Public fromJSONString | ||||||
fromJSONString(value: string)
|
||||||
populate objects and values from JSON. bulk import basically. example shows bulk importing from local storage. Example :
Parameters :
Returns :
void
|
Public toJSONObject |
toJSONObject()
|
get shallow JSON copy of services object state by calling same method on namespace members. Example :
Returns :
SzSdkPrefsModel
|
Public toJSONString |
toJSONString()
|
get a serialized JSON string from current instance. bulk export.
Returns :
string
|
Public Optional admin |
Type : SzAdminPrefs
|
Default value : new SzAdminPrefs()
|
instance of SzAdminPrefs |
Public Optional dataMart |
Type : SzDataMartPrefs
|
Default value : new SzDataMartPrefs()
|
instance of SzGraphPrefs |
Public Optional entityDetail |
Type : SzEntityDetailPrefs
|
Default value : new SzEntityDetailPrefs()
|
instance of SzEntityDetailPrefs |
Public Optional graph |
Type : SzGraphPrefs
|
Default value : new SzGraphPrefs()
|
instance of SzGraphPrefs |
Public Optional how |
Type : SzHowPrefs
|
Default value : new SzHowPrefs()
|
instance of SzHowPrefs |
Public prefChanged |
Type : Subject<literal type>
|
Default value : new Subject<{name: string, value: any}>()
|
subscribe for state change representation. |
Public prefsChanged |
Type : BehaviorSubject<SzSdkPrefsModel>
|
Default value : new BehaviorSubject<SzSdkPrefsModel>( this.toJSONObject() )
|
subscribe for state change representation. |
Public Optional searchForm |
Type : SzSearchFormPrefs
|
Default value : new SzSearchFormPrefs()
|
instance of SzSearchFormPrefs |
Public Optional searchResults |
Type : SzSearchResultsPrefs
|
Default value : new SzSearchResultsPrefs()
|
instance of SzSearchResultsPrefs |