• Robert Knight's avatar
    Make construction method for objects in `Injector` explicit · 947a2acc
    Robert Knight authored
    Previously a heuristic based on function naming was used to determine
    whether `Injector` should construct objects with `new` or not. This is
    brittle because compiler transforms may alter function names (eg. terser
    removes them by default).
    
    This commit re-works the API so that the caller explicitly indicates how
    the object should be created (the "provider" to use). As a convenience
    if a function is passed it is assumed to be a class.
    
    ```
    // Register a class.
    register("anObject", SomeClass);
    register("anObject", { class: SomeClass });
    
    // Register a factory.
    register("anObject", { factory: makeMeAnObject });
    
    // Register a plain value.
    register("anObject", { value: "foobar" });
    ```
    947a2acc
injector-test.js 4.47 KB