Skip to content

ember-resources@5.6.2

Compare
Choose a tag to compare
@github-actions github-actions released this 21 Jan 22:34
· 727 commits to main since this release
c9fe1eb

Patch Changes

  • #742 dd7234a Thanks @NullVoxPopuli! - When using the resourceFactory (blueprint in Starbeam terms),
    there was an issue where a returned resource would not get torn down when the
    surrounding context of the resourceFactory would get torn down.

    For example, in this situation,
    which has been added as the second example on this blog post,

    const poll = resourceFactory((fn, interval) => {
      return resource(({ on }) => {
        let x = setInterval(fn, interval);
        on.cleanup(() => clearInterval(x));
      });
    });

    usage would be:

    {{poll someFn someSeconds}}

    So, when this was in an if statement, or in a component or route, or any content that could be torn down,
    the on.cleanup callback would not be called.

    This fix addresses the issue and the on.cleanup callback is now called.

    NOTE: this approach to using resources is equivelent to this 0-dependency solution to polling:

    import Component from "@glimmer/component";
    import Helper from "@ember/component/helper";
    import type RouterService from "@ember/routing/router-service";
    import { service } from "@ember/service";
    
    class Poll extends Helper {
      compute([fn, interval]: [(...args: unknown[]) => unknown, number]) {
        let x = setInterval(fn, interval);
        registerDestructor(this, () => clearInterval(x));
      }
    }
    
    export default class Demo extends Component {
      @service declare router: RouterService;
    
      poll = Poll;
      refreshData = () => this.router.refresh();
    }
    {{this.poll this.refreshData 4000}}