-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9e592e
commit 634c78f
Showing
4 changed files
with
214 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { buildCapabilities } from '../util/capabilities'; | ||
|
||
import type { CapturedArguments as Arguments, HelperCapabilities } from '@glimmer/interfaces'; | ||
|
||
type FnArgs<Args extends Arguments = Arguments> = | ||
| [...Args['positional'], Args['named']] | ||
| [...Args['positional']]; | ||
|
||
interface FunctionHelperState<Args extends Arguments = Arguments> { | ||
fn: <Return>(...args: FnArgs<Args>) => Return; | ||
args: Args; | ||
} | ||
|
||
export class FunctionHelperManager<State extends FunctionHelperState> { | ||
capabilities = buildCapabilities({ | ||
hasValue: true, | ||
hasDestroyable: false, | ||
hasScheduledEffect: false, | ||
}) as HelperCapabilities; | ||
|
||
createHelper(fn: State['fn'], args: State['args']) { | ||
return { fn, args }; | ||
} | ||
|
||
getValue({ fn, args }: State) { | ||
if (Object.keys(args.named).length > 0) { | ||
let argsForFn: FnArgs<Arguments> = [...args.positional, args.named]; | ||
|
||
return fn(...argsForFn); | ||
} | ||
|
||
return fn(...args.positional); | ||
} | ||
|
||
getDebugName(fn: State['fn']) { | ||
if (fn.name) { | ||
return `(helper function ${fn.name})`; | ||
} | ||
|
||
return '(anonymous helper function)'; | ||
} | ||
} |
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
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