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)

Booting

By default, a concern class is ONLY instantiated when you interact with its properties or methods, which have been "aliased" into a target class (aka. lazy booting).

class ContactsApi extends AbstractConcern {
    get users() { /* ...not shown here... */}
}

@use(ContactsApi) // Concern is NOT instantiated
class UsersRegistry {}

const users = (new UsersRegistry()).users; // Concern is instantiated

Manual Booting

You can use the bootConcerns() utility to manually boot concerns. It accepts the following arguments:

  • instance: object|Owner - The target class instance that uses the concerns.
  • ...concerns: ConcernConstructor[] - List of concern classes to instantiate (aka. boot).
import { use, bootConcerns } from "@aedart/support/concerns";

@use(
    ConcernA,
    ConcernB,
    ConcernC,
)
class Target {
    constructor() {
        bootConcerns(this, ConcernA, ConcernB);
    }
}

const instance = new Target(); // ConcernA and ConcernB are instantiated

warning

If you attempt to boot a concern that has already been booted, a BootError will be thrown!

To determine if a concern has already been booted, use the concern container's hasBooted() method.

import {
    getContainer,
    bootConcerns
} from "@aedart/support/concerns";

class Record extends ApiService {
    constructor() {
        super();
        
        if (!getContainer(this).hasBooted(ApiConnection)) {
            bootConcerns(this, ApiConnection);
        }
    }
}

See Manual interaction for details.

Boot All Concerns

If you wish to boot all concerns, use the bootAllConcerns() utility.

import { use, bootAllConcerns } from "@aedart/support/concerns";

@use(
    ConcernA,
    ConcernB,
    ConcernC,
)
class Target {
    constructor() {
        bootAllConcerns(this);
    }
}

const instance = new Target(); // All concerns are initialised
Edit page
Last Updated:
Contributors: alin
Prev
Conflict Resolution
Next
Hooks