Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version Packages #185

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented May 30, 2024

This PR was opened by the Changesets release GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or setup this action to publish automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to develop, this PR will be updated.

Releases

@freshgum/[email protected]

Major Changes

  • 40c0f8c: This is a breaking change to the core API.

    The container no longer provides a default containerId parameter for the following methods:

    • ContainerInstance.ofChild
    • ContainerInstance.of
    • static ContainerInstance.of

    In retrospect, this was a bad idea. I'll explain this further with the code below.

    import { Container } from '@freshgum/typedi';
    
    const c1 = Container.ofChild(Symbol('c1'));
    
    @Service({ container: c1 }, [])
    class MyService {}
    
    const c2 = c1.ofChild();
    
    c2.get(MyService); // -> ServiceNotFoundError

    Ignoring the hints above, the problem with this code may not be obvious at a first glance.
    While you'd assume the call to c1.ofChild() returns a child container of c1 (which
    would then inherit its services), it's actually just returned an exact reference to the
    default container (Container itself.)

    This raises a great deal of ambiguity, as it's no longer immediately clear whether a call
    to these methods does as you would initially expect.

    Therefore, type-safe calls to these methods without a container ID will now raise an error at
    compile-time.
    The signature of these methods has been changed to require the container ID parameter.

    Migrating away from this behaviour is quite simple: replace all calls to X.ofChild()
    with a reference to the default container (Container).

    Whilst I'm not a fan of making breaking changes to the Container, I believe this one makes
    sense in the pursuit of a safer, more streamlined API -- if you experience any issues with
    this, please feel free to open a GitHub issue.

Minor Changes

  • e70148c: The lazy function has been renamed to forwardRef.

    In retrospect, the name of this function didn't clearly
    describe its purpose, which is to break cyclic dependency
    chains at the service initialization stage.

    The renaming of this function to forwardRef more clearly
    explains its function. The name was 1:1 inspired by Angular,
    which contains a function that does exactly the same thing.

    Note that, while lazy is deprecated, it will still be supported.
    The implementation of the lazy function has been moved to
    forwardRef, which is a 1:1 replacement for the former.

Patch Changes

  • 02fe3cc: The code for virtual tokens (such as HostContainer()) has been moved into individual tokens,
    as opposed to hosting logic for these tokens in ContainerInstance.

    This means that we no longer have to check for individual tokens in the container's
    .get code-path, which has historically been the case.

    Instead, logic for these tokens is now moved into special tokens called Executable Tokens.

    This yields numerous advantages, one of which being that, should a certain special token go
    unused, its code can safely be removed from a bundle via dead-code elimination.

    While this is mostly an internal change, the concept of Executable Tokens works quite well,
    and so I'm considering making it part of the public API surface + documentation after further testing.

  • ad8f4f6: Dedicated entry-points have been added for web-facing builds (#184).
    You're now able to use modules from contrib/ without relying on a bundler,
    or importing contrib/ packages separately from /esm5/.

    [!NOTE] > The changes made here do not impact current UMD / MJS entry-points.

    If you're using these, you won't experience any changes.
    To make use of contrib/ modules, you'll need to switch to the new builds shown above.

    The new entry-points are as follows (all files are under ./build/bundles/):

    • typedi.full.min.mjs (ES Module format.)
    • typedi.full.mjs
    • typedi.umd.full.js (UMD modules.)
    • typedi.umd.full.min.js

    You can now do the following:

    import Container, { Contrib } from 'https://unpkg.dev/@freshgum/typedi/build/bundles/typedi.full.mjs';
    
    // Let's use some modules:
    const { TransientRef, ES } = Contrib;
    assert(TransientRef.TransientRefHost);

    The same can be done using UMD modules, like so:

    <!doctype html>
    <html>
      <head>
        <!-- ... -->
      </head>
      <body>
        <!-- Be sure to use subresource integrity in production! ;-) -->
        <script src="https://unpkg.dev/@freshgum/typedi/build/bundles/typedi.umd.full.min.js"></script>
        <script>
          const { Container, Contrib } = TypeDI;
          // ...
        </script>
      </body>
    </html>

    [!TIP]
    If you've noticed, you can actually import the Container through unpkg!

    Here's a link to the latest bundles: https://unpkg.dev/browse/@freshgum/typedi/build/bundles/


    I've been wanting to implement this for a while, but life has repeatedly found itself in the way.
    When spending some time on it, it was mostly a simple job: the majority of the work lied in creating
    a new build step to generate a barrel file for contrib/, and then integrating Rollup with that.

    If you're interested, the original code for this lies in #184. It's actually quite interesting!

@github-actions github-actions bot force-pushed the changeset-release/develop branch from 3e32380 to 35b2c67 Compare June 5, 2024 23:38
@github-actions github-actions bot force-pushed the changeset-release/develop branch 14 times, most recently from 755c515 to fa27f36 Compare July 1, 2024 21:52
@github-actions github-actions bot force-pushed the changeset-release/develop branch 2 times, most recently from 0bbf51e to 98fdbea Compare July 6, 2024 21:41
@github-actions github-actions bot force-pushed the changeset-release/develop branch from 98fdbea to 12abeed Compare July 23, 2024 12:19
@github-actions github-actions bot force-pushed the changeset-release/develop branch 6 times, most recently from c87d8cd to 0a0efed Compare August 4, 2024 00:42
@github-actions github-actions bot force-pushed the changeset-release/develop branch from 0a0efed to 567753e Compare August 27, 2024 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants