Reactive Event Driven Actions with Firefly Semantics Slice

Ole Ersoy
1 min readFeb 24, 2021
Image by Ronny Overhate from Pixabay

Scenario

If a user visits our app and the user is already signed in, then we want to redirect the user to the /app route.

We will be using a Firefly Semantics Slice Object Store to implement the reactive event handling.

Approach

The below onAuthRedirectToApplication utility method takes a route argument and directs to it when the user is already signed in.

/**
* Redirect the user to the application
* when the user is authenticated.
* @param route
*/
public onAuthRedirectToApplication(route:string) {this.s.OS.S.IS_AUTHENTICATED.obs.subscribe(auth => {
auth && this.r.navigate([route])
})
}

Note that when the application loads it should check whether the user is signed in, and if so perform a put on the Slice Object Store instance modeling the IS_AUTHENTICATED parameter. For example:

this.s.OS.put(this.s.OS.S.IS_AUTHENTICATED, true)

Brought to You By

--

--