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

Release Preview #743

Merged
merged 1 commit into from
Jan 21, 2023
Merged

Release Preview #743

merged 1 commit into from
Jan 21, 2023

Conversation

github-actions[bot]
Copy link
Contributor

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

Releases

[email protected]

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}}

@NullVoxPopuli NullVoxPopuli merged commit c9fe1eb into main Jan 21, 2023
@NullVoxPopuli NullVoxPopuli deleted the changeset-release/main branch January 21, 2023 22:28
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.

1 participant