IonIon
Packages
  • next
  • current
Changelog
GitHub
Packages
  • next
  • current
Changelog
GitHub
  • Version 0.x

    • Release Notes
    • Upgrade Guide
    • Contribution Guide
    • Security Policy
    • Code of Conduct
    • Origin
  • Packages

    • Introduction
    • Container

      • Introduction
      • Prerequisites
      • How to install
      • Container Instance
      • Bindings
      • Dependencies
      • Resolving
      • Contextual Bindings
    • Contracts

      • Introduction
      • How to install
    • Support

      • Introduction
      • How to install
      • Arrays

        • About Arrays
        • Includes All
        • Includes Any
        • Is Array Like
        • Is Concat Spreadable
        • Is Safe Array Like
        • Is Typed Array
        • Merge
      • Concerns

        • About Concerns
        • Prerequisites
        • Concern Class
        • Using Concerns
        • Aliases
        • Conflict Resolution
        • Booting
        • Hooks
        • Edge Cases
        • JSDoc
      • Exceptions

        • About Exceptions
        • Configure Custom Error
        • Configure Stack Trace
        • Get Error Message
        • Custom Errors
      • Facades

        • About Facades
      • Meta

        • About Meta
        • Prerequisites
        • Supported Elements
        • Set & Get
        • Inheritance
        • Outside Changes
        • TC39 Proposal
        • Target Meta
      • Mixins

        • About Mixins
        • New Mixin
        • Apply Mixins
        • Instanceof
        • Inheritance
        • Onward
      • Object

        • About Objects
        • Forget
        • Forget All
        • Get
        • Has
        • Has All
        • Has Any
        • Has Unique ID
        • Is Cloneable
        • Is Populatable
        • Isset
        • Merge
        • Populate
        • Set
        • Unique ID
      • Reflections

        • About reflections
        • Assert Has Prototype Prop.
        • Class Looks Like
        • Class Own Keys
        • Get All Parents Of Class
        • Get Class Prop. Descriptor
        • Get Class Prop. Descriptors
        • Get Constructor Name
        • Get Name Or Desc. Tag
        • Get Parent Of Class
        • Has All Methods
        • Has Method
        • Has Prototype Property
        • Is Callable
        • Is Class Constructor
        • Is Class Method Reference
        • Is Constructor
        • Is Key Safe
        • Is Key Unsafe
        • Is Method
        • Is Subclass
        • Is Subclass Or Looks Like
        • Is WeakKind
      • Misc

        • About Misc.
        • Desc. Tag
        • Empty
        • Is Key
        • Is Primitive
        • Is Property Key
        • Isset
        • Merge Keys
        • To Weak Ref.
      • Callback Wrapper
    • Vuepress Utils

      • Introduction
      • How to install
      • Navigation

        • Archive
      • Plugins

        • Last Updated
      • Components

        • Version Disclaimer
    • XYZ (test package)

Hooks

Concerns offer a few hook methods. These can be used to perform advanced setup or initialisation logic.

  • BEFORE Registration
  • AFTER Registration

BEFORE Registration

To perform pre-registration logic, use the static BEFORE method in your concern class. This hook method is invoked before the concern container and aliases are defined in the target class.

The method accepts the following arguments:

  • target: UsesConcerns - the target class (class constructor!).
import { BEFORE } from "@aedart/contracts/support/concerns";
import { AbstractConcern } from "@aedart/support/concerns";
import { isSubclass } from '@aedart/support/reflections';

import { JobHandler } from '@acme/jobs';

class RecordsJobs extends AbstractConcern {
    
    static [BEFORE](target) {
        // E.g. prevent this concern from being used by all kinds of targets...
        if (!isSubclass(target, JobHandler)) {
            throw new TypeError('RecordsJobs can only be used by JobHandler');
        }
    }
}

AFTER Registration

To perform post-registration logic, use the static AFTER method in your concern class. This method is invoked after the concern container and aliases have been defined in target's prototype.

The method accepts the following arguments:

  • target: UsesConcerns - the target class (class constructor!).
import { AFTER } from "@aedart/contracts/support/concerns";
import { AbstractConcern } from "@aedart/support/concerns";

import { ApiConnection } from '@acme/api';

class RecordsJobs extends AbstractConcern {
    
    static [AFTER](target) {
        // E.g. init or setup static resources...
        ApiConnection.init();
    }
}
Edit page
Last Updated:
Contributors: alin
Prev
Booting
Next
Edge Cases