Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

WIP - feat($injector): add support for non-string IDs (and other minor stuff) #14998

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Commits on Aug 6, 2016

  1. Configuration menu
    Copy the full SHA
    ab325a0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2e0441d View commit details
    Browse the repository at this point in the history
  3. test($injector): fix incorrect test and error message assertions

    Fix a test that was never run.
    Ensure the assertions for `$injector:cdep`/`$injector:unpr` errors test the whole path.
    gkalpak committed Aug 6, 2016
    Configuration menu
    Copy the full SHA
    a9863bf View commit details
    Browse the repository at this point in the history
  4. feat($injector): add support for non-string IDs

    Previously, only strings could be used as identifiers for Angular services. This commit adds support
    for using any value as identifier for an Angular service (e.g. used with `.provider()`,
    `.factory()`, `.service()`, `.value()`, `.constant()`, `.decorator()`).
    
    Among other things, non-string identifiers enable:
    - Private services (without relying on naming conventions).
    - Collision avoidance (without relying on custom prefixes and namespacing).
    - Better toolability (e.g. autocomplete support for service identifiers).
    - Better compression (i.e. strings can't be minified, non-string values could).
    
    Identifiers for directives and filters are still restricted to string values, since they need to be
    referenced in HTML (text).
    
    --
    For services with string IDs, the corresponding provider ID is constructed by appending `Provider`
    to the service ID. For services with non-string IDs, the corresponding provider has the exact same
    ID (it is the context that determines if a service or a provider should be injected).
    
    E.g.:
    ```js
    var bar = {};
    
    angular.
      module('myModule', []).
    
      provider('foo' /* string ID     */, {$get: function () { return 'FOO'; }}).
      provider( bar  /* non-string ID */, {$get: function () { return 'BAR'; }}).
    
      config(['fooProvider', function (fooProvider) {
        // `foo` provider injected (because we are in config block)
      }]).
      run(['foo', function (foo) {
        // `foo` service injected (because we are in run block)
      }]).
    
      config([bar, function (barProvider) {
        // `bar` provider injected (because we are in config block)
        // (even though we used the same identifier (`bar`) that we will use in the run block)
      }]).
      run([bar, function (bar) {
        // `bar` service injected (because we are in run block)
      }]);
    ```
    
    --
    This change is backwards compatible (afaict).
    
    Fixes angular#10347
    gkalpak committed Aug 6, 2016
    Configuration menu
    Copy the full SHA
    32bde2d View commit details
    Browse the repository at this point in the history