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)

Aliases

In this context, an "alias" is a proxy property or method inside a target class. It is responsible for forwarding interaction to the original property or method, inside the concern class instance. Aliases are created automatically by the use() class decorator.

  • Properties & Methods
  • If property or method already exists

Properties & Methods

When injecting a concern into a target class, the concern's public properties and methods are defined as "aliases" (aka. proxy properties or methods), in the target class' prototype (see PROVIDES symbol for additional details).

Consider the following example:

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

class Levels extends AbstractConcern {
    get level() { /* ...not shown */ }
    set level(value) { /* ...not shown */ }
    clear() { /* ...not shown */ }
}

@use(Levels)
class Recorder {}

The aliasing mechanism will transform the target class into something that very roughly corresponds to this:

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

class Levels extends AbstractConcern {
    get level() { /* ...not shown */ }
    set level(value) { /* ...not shown */ }
    clear(level) { /* ...not shown */ }
}

class Recorder {
    // ...private concerns container not shown...

    // get level "alias"
    get level() {
        return this[CONCERNS].get(Levels)['level'];
    }

    // set level "alias"
    set level(value) {
        this[CONCERNS].get(Levels)['level'] = value;
    }

    // method clear "alias"
    clear(...args) {
        return this[CONCERNS].get(Levels)['clear'](...args);
    }
}

See Manual interaction and Conflict Resolution for additional details.

If property or method already exists

When a property or method from a concern already exists in the target class' prototype chain¹, then NO Alias is defined. Said differently, the use() class decorator does NOT overwrite a target class' properties or methods.

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

@use(Label) // Label's "name" property is NOT aliased
class Battery {

    // Battery's get/set "name" remains untouched by concern
    get name() { /* ...not shown.. */ }
    set name(v) { /* ...not shown.. */ }
}

¹: Inherited properties and methods are also respected.

See Conflict Resolution for additional details.

Edit page
Last Updated:
Contributors: alin
Prev
Using Concerns
Next
Conflict Resolution