Skip to content

ember-resources@6.0.0-beta.2

Pre-release
Pre-release
Compare
Choose a tag to compare
@github-actions github-actions released this 10 Mar 01:16
· 547 commits to main since this release
9b81a69

Minor Changes

  • #797 18adb86 Thanks @NullVoxPopuli! - Add link() and @link, importable from ember-resources/link.

    NOTE: for existing users of ember-resources, this addition has no impact on your bundle.

    Example property usage
    import { link } from 'ember-resources/link';
    
    class MyClass {  ... }
    
    export default class Demo extends Component {
      // This usage does now allow passing args to `MyClass`
      @link(MyClass) myInstance;
    }
    Example inline usage
    import Component from "@glimmer/component";
    import { cached } from "@glimmer/tracking";
    import { link } from "ember-resources/link";
    
    export default class Demo extends Component {
      // To pass args to `MyClass`, you must use this form
      // NOTE though, that `instance` is linked to the `Demo`s lifecycle.
      //  So if @foo is changing frequently, memory pressure will increase rapidly
      //  until the `Demo` instance is destroyed.
      //
      //  Resources are a better fit for this use case, as they won't add to memory pressure.
      @cached
      get myFunction() {
        let instance = new MyClass(this.args.foo);
    
        return link(instance, this);
      }
    }

    This abstracts away the following boilerplate:

    import { getOwner, setOwner } from "@ember/owner";
    import { associateDestroyableChild } from "@ember/destroyable";
    
    class MyClass {
      /* ... */
    }
    
    export default class Demo extends Component {
      @cached
      get myInstance() {
        let instance = new MyClass();
    
        associateDestroyableChild(this, instance);
    
        let owner = getOwner(this);
    
        if (owner) {
          setOwner(instance, owner);
        }
    
        return instance;
      }
    }