Created
September 30, 2022 06:14
-
-
Save patricklx/4b42a43e04176a14b7e76d91c65b133c to your computer and use it in GitHub Desktop.
helper for resource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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