Skip to content

Instantly share code, notes, and snippets.

@patricklx
Created September 30, 2022 06:14
Show Gist options
  • Save patricklx/4b42a43e04176a14b7e76d91c65b133c to your computer and use it in GitHub Desktop.
Save patricklx/4b42a43e04176a14b7e76d91c65b133c to your computer and use it in GitHub Desktop.
helper for resource
import Helper from '@ember/component/helper';
import { registerDestructor, unregisterDestructor } from '@ember/destroyable';
export default class GenericHelper extends Helper {
compute(positional, named) {
const firstTime = !this.updateCallback;
this.updateCallback = named.update;
if (named.teardown) {
if (this.teardownCallback) {
unregisterDestructor(this, this.teardownCallback);
}
this.teardownCallback = named.teardown;
registerDestructor(this, this.teardownCallback);
}
if (this.updateCallback && !firstTime) {
this.updateCallback();
}
if (firstTime && named.create) {
named.create();
}
//access all positional params
positional.forEach(() => null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment