Smart Service Adapter

The Smart Service Adapter service provides an easy way to manage the JSDO session and JSDO catalogs, login/logout functionality and publishes state changes so that your app can respond to them.

 

Login/Logout

import { SmartServiceAdapter } from '@consultingwerk/smartcomponents-core';
 
 
constructor(private serviceAdapter: SmartServiceAdapter) { }
 
doLogin(username: string, password: string) {
	this.serviceAdapter.login({ username: username, password: password })
			.then(() => { //login successfull })
			.catch(() => { //login failed });
}
 
doLogout() {
	this.serviceAdapter.logout()
			.then(() => { //success })
			.catch(() => { //failed });
});

 

Adding a JSDO Catalog

import { SmartServiceAdapter } from '@consultingwerk/smartcomponents-core';




constructor(private serviceAdapter: SmartServiceAdapter) { }


ngOnInit() {
	this.serviceAdapter.addCatalog('myCatalog')
			.then(() => { //success })
			.catch(() => { //failed });
}

 

Subscribing to state changes

When the Smart Service Adapter's state changes, it is published to any subscribers. The event argument is of class SmartServiceAdapterState.

import { SmartServiceAdapter } from '@consultingwerk/smartcomponents-core';




constructor(private serviceAdapter: SmartServiceAdapter) { }
 
ngOnInit() {
	this.serviceAdapter.filter(state => !!state /** ensure the state is not null */).subscribe(state => {
		if (state.authenticated) {
			//do something once the user has logged in
		} else {
			//do something once the user has logged out
		}
	});
}