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)

Conflict Resolution

  • Naming Conflicts
  • Resolve Naming Conflicts
  • Prevent Aliases
  • Shorthand Configuration

Naming Conflicts

A concern class may ONLY occur once in a target class' prototype chain. This is a core feature of the concerns mechanism and cannot be circumvented. However, sometimes you may find yourself in situations where different injected concern classes define the same property or method name. When this happens an AliasConflictError is thrown.

class Label extends AbstractConcern {
    get name() { /* ...not shown.. */ }
    set name(v) { /* ...not shown.. */ }
}

class Category extends AbstractConcern {
    get name() { /* ...not shown.. */ }
    set name(v) { /* ...not shown.. */ }
}

@use(
    Label,
    Category // AliasConflictError: Alias "name" for property ...
)
class Battery {}

Resolve Naming Conflicts

To resolve the previous shown naming conflict, you can specify custom "aliases" when injecting a concern class, via an injection configuration object.

// ... Label and Category concerns not shown ...

@use(
    Label,
    {
        concern: Category,
        aliases: {
            'name': 'category' // Alias Category's "name" property as "category"
        }
    }
)
class Battery {}

const instance = new Battery();
instance.name = 'AAA';
instance.category = 'Rechargeable';

The aliases option is key-value record, where;

  • key = property key in the concern class.
  • value = property key (alias) to define in the target class.

Prevent Aliases

To prevent a concern class from defining any aliases inside a target class, set the allowAliases option to false.

import { getConcernsContainer } from "@aedart/support/concerns";

@use(
    Label,
    {
        concern: Category,
        allowAliases: false // Category's "name" is NOT aliased in target
    }
)
class Battery {}

const instance = new Battery();
instance.name = 'AA';

// Interact with Category concern to set "name"
getConcernsContainer(instance).get(Category).name = 'Rechargeable';

Shorthand Configuration

You can also use a shorthand version to specify a concern injection configuration, via an array. The first array value must always be the concern class that must be injected. The second value can either be an aliases object, or boolean value for setting the allowAliases option.

@use(
    Label,
    [Category, {
        'name': 'category'
    }]
)
class Battery {}

And to prevent a concern from defining aliases in a target:

@use(
    Label,
    [Category, false]
)
class Battery {}
Edit page
Last Updated:
Contributors: alin
Prev
Aliases
Next
Booting