crfsa-core-module
v0.0.10
Published
Core Module for Carrefour Application
Downloads
3
Readme
Running unit tests
Run ng test
to execute the unit tests via Karma.
Bootstrapping the Core Module (Happens in main application)
Step 1: Importing it into your project's app.module.ts
file
import {CarrefourCoreModule} from 'crfsa-core-module';
After adding this import statement, you have to add it to the imports
of your app.module.ts
.
Something along these lines:
@NgModule({
...
imports: [
CarrefourCoreModule
]
...
})
Now you have all of the Core Module's exposed functionality within your project.
But, there are a couple more things to do in order to get your module working with the Core Module.
Step 2: Initializing the Bootstrapping process of the CoreModule
In order for the Core Module to start it's Bootstrapping functionality, you have to call startInitialization
on the CoreModuleBootstrapService
TIP: Do this within the ngOnInit
lifecycle within you app.component.ts
to trigger it properly.
import {CoreModuleBootstrapService} from 'crfsa-core-module';
export class AppComponent implements OnInit {
...
constructor(private coreModuleBootstrapService: CoreModuleBootstrapService) {
}
...
ngOnInit() {
this.coreModuleBootstrapService.startInitialization(
[
...
'CoreModule',
'AuthModule',
...
// Here is where you specify the names of all modules you're going to be using within your app: this is an Array<string>
]
)
}
...
}
NOTE: this bootstrapping/nitializing happens only once within the carrefour application, this is not done from within any module. A module's job is not to handle the bootstrapping, the bootstrapping is handled by the lifecycle of the main application aka the rootPage
's ngOnInit
lifecycle.
Registering a module in the Core Module (Happens within modules)
Here's some example code to illustrate how this happens:
listenForRegistrationEvent() {
// Add a listener to the 'crf_module_init' browser event to trigger the module registry process
document.addEventListener("crf_module_init", (event: any) => {
// Get the register function from the event.detail property
const register: (registrationData: ModuleRegistrationData, callback: any)=> void = event.detail;
const moduleData: ModuleRegistrationData = {
name: 'TestModule', // Set the name of the module to be registered
version: '0.0.1', // Set the registration version of the module, all versions of all modules must match
eventTypes: [
...
'test/example/event',
'test/api/onResponse', // These are needed to register the events in the Event Bus
'test/api/request'
...
],
isInitialModule: false, // Only 1 module can be the Initial Module
isAuthenticationModule: false // Only 1 module can be the authenticationModule
}
// Call registration function with the moduleData variable to register it
register(moduleData, (eventBus) => {
this.bus = eventBus; // if everything goes right, this callback should be called and you are now granted the event bus
});
});
}