ember-resources@5.6.2
github-actions
released this
21 Jan 22:34
·
727 commits
to main
since this release
Patch Changes
-
#742
dd7234a
Thanks @NullVoxPopuli! - When using theresourceFactory
(blueprint in Starbeam terms),
there was an issue where a returnedresource
would not get torn down when the
surrounding context of theresourceFactory
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:
So, when this was in an
if
statement, or in a component or route, or any content that could be torn down,
theon.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(); }