-
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
6f9b8b1
commit c4b2975
Showing
2 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { CAPABILITIES, CapturedArguments as Arguments } 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 = { | ||
[CAPABILITIES]: true, | ||
hasValue: true, | ||
hasDestroyable: false, | ||
hasScheduledEffect: false, | ||
} as const; | ||
|
||
createHelper(fn: State['fn'], args: State['args']) { | ||
return { fn, args }; | ||
} | ||
|
||
getValue({ fn, args }: State) { | ||
let argsForFn: FnArgs<Arguments> = [ | ||
...args.positional, | ||
Object.keys(args.named).length > 0 ? args.named : {}, | ||
]; | ||
|
||
return fn(...argsForFn); | ||
} | ||
|
||
getDebugName(fn: State['fn']) { | ||
return fn.name || '(anonymous 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