import { decoratorWithRequiredParams , DecoratorDescriptor } from '@ember-decorators/utils/decorator' ; import { assert } from '@ember/debug' ; import { get , computed } from '@ember/object' ; task lastValue lastValue function param { string } taskName export default decoratorWithRequiredParams ( function lastValue < Target extends object > ( target , key , desc , [ taskName ] ) : DecoratorDescriptor { assert ( `ember-concurrency-decorators: @lastValue expects a task name as the first parameter.` , typeof taskName === 'string' ) ; const { initializer } = desc ; delete desc . initializer ; const cp = computed ( `${ taskName }.lastSuccessful` , function ( ) { const lastInstance = get ( this , `${ taskName }.lastSuccessful` ) ; if ( lastInstance ) { return get ( lastInstance , 'value' ) ; } if ( initializer ) { return initializer . call ( this ) ; } return undefined ; } ) ; return cp ( target , key , desc ) ; } ) as ( taskName : string ) => PropertyDecorator ;