Skip to content

D. Modules

Jonathan Casarrubias edited this page May 3, 2018 · 1 revision

alt text

Description

In this section, you will learn how to create and configure an OnixJS Module.

An OnixJS Module is simply a decorated class that won't really provide any functionality or logic, but it will serve to install several types of artifacts that you later will develop in order to actually create your functionality.

Scope

When you install the different available API Artifacts within an OnixJS Module, you will require understanding that you are creating a scope, which means that any installed artifact won't be accessible within other modules.

Module Example

import { Module } from '@onixjs/core';

@Module({
  models: [],
  services: [],
  renderers: [],
  components: []
  // Optional module level lifecycle
  // will execute on every RPC Call or Stream, for any component
  // within this module.... do your magic here. :)
  lifecycle: async (app, metadata, method): Promise<any> => {
    // before call
    const result = await method();
    // after call
    console.log('Custom Logger: ', result);
    return result;
  }
})
export class MainModule {}

Options

  • models: (Injectable) An array of OnixJS Model Classes.
  • services: (Injectable) An array of OnixJS Service Classes.
  • renderers: (Injectable) An array of OnixJS Renderer Classes.
  • components: An array of OnixJS Component Classes.
  • lifecycle: A system hook to pre and post process rpc and stream calls.

How to create each of those classes will be described in their own section.

Clone this wiki locally