Skip to content

03. Modularity System

ali badakhshan edited this page Jun 13, 2019 · 5 revisions

Narik Modularity System

Narik provides you with a modular application. this means you can divide your application to different modules and each module has its own metadata.

To define a Narik Module your angular class must extend NarikModule

export class MainAdminModule extends NarikModule

NarikModule is an abstract class. you should override two abstract properties

abstract readonly key: string;
abstract readonly moduleInfo: Observable<ModuleInfo>;

key: The key of the module. Must be unique inside application.

moduleInfo: Information about the module (Module Metadata). for this property, you should return the module's metadata. You can do this in any way, but the base class provides you with some helper methods. You can use any of them.

protected loadInfoFromJson(): Observable<ModuleInfo>;
protected loadInfoFromData(info: ModuleInfo): Observable<ModuleInfo>;

loadInfoFromJson: load module's metadata from remote json file.
from where? you specify it in ConfigService.

loadInfoFromData: load module's metadata from plain JSON.

Finally, your module class will be like this

const moduleKey = "main-admin";

export class MainAdminModule extends NarikModule {
  constructor(injector: Injector) {
    super(injector);
  }

  get key() {
    return moduleKey;
  }
  get moduleInfo(): Observable<ModuleInfo> {
    return this.loadInfoFromJson();
  }
}

If your Narik module is also an Angular Module(@NgModule)
(at this time all Narik module are angular module) you can provide two options in Module Providers.

{
    provide: MODULE_UI_KEY,
    useValue: moduleKey
},
{
    provide: MODULE_DATA_KEY,
    useValue: "IBN"
}

MODULE_UI_KEY: Many UI components use this option to know from which module's metadata, they should read whatever they want.

for example, you have two modules: ModuleA and ModuleB. and in metadata that Related to UI like "uiDefaultOptions" they are same. you define these metadata only for ModuleA and in ModuleB you provide "ModuleA" for MODULE_UI_KEY. With this, you say that with metadata related to UI, ModuleA uses ModuleB's metadata.

MODULE_DATA_KEY : Many Data services use this option to know from which module's metadata, they should read whatever they want.

for example, you have two modules: ModuleA and ModuleB. and in metadata that Related to DATA like "dataItems" they are same. you define these metadata only for ModuleA and in ModuleB you provide "ModuleA" for MODULE_DATA_KEY. With this, you say that with metadata related to DATA, ModuleA uses ModuleB's metadata.

More Information about Narik Metadata Framework

You can see more complete examples in these Narik samples and starters

narik-material-starter
narik-material-demo
narik-devextreme-demo
narik-devextreme-starter
narik-ng-bootstrap-demo
narik-primeng-demo
narik-nebular-demo