-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Showing
8 changed files
with
150 additions
and
31 deletions.
There are no files selected for viewing
7 changes: 2 additions & 5 deletions
7
packages/@ember/-internals/glimmer/lib/helpers/internal-helper.ts
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 |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import type { InternalOwner } from '@ember/-internals/owner'; | ||
import type { Helper, HelperDefinitionState } from '@glimmer/interfaces'; | ||
// import { setInternalHelperManager } from '@glimmer/manager'; | ||
import { setInternalHelperManager } from '@glimmer/manager'; | ||
|
||
export function internalHelper(helper: Helper<InternalOwner>): HelperDefinitionState { | ||
return function () { | ||
console.log('internal helper', this, [...arguments]); | ||
return helper(...arguments); | ||
} | ||
return setInternalHelperManager(helper, {}); | ||
} |
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
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,63 @@ | ||
function argsProxyFor(capturedArgs: any, type: string) { | ||
return new Proxy(capturedArgs, { | ||
get(target, prop) { | ||
if (prop === 'named') { | ||
return {}; | ||
} else if (prop === 'positional') { | ||
return target; | ||
} else { | ||
throw new Error(`Cannot get ${prop} from ${type} args`); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
export class CustomHelperManager { | ||
factory: (owner: unknown) => any; | ||
constructor(factory: (owner: unknown) => any) { | ||
this.factory = factory; | ||
} | ||
private helperManagerDelegates = new WeakMap<O, any>(); | ||
private undefinedDelegate: any | null = null; | ||
|
||
private getDelegateForOwner(owner: any) { | ||
let delegate = this.helperManagerDelegates.get(owner); | ||
|
||
if (delegate === undefined) { | ||
let { factory } = this; | ||
delegate = factory(owner); | ||
|
||
this.helperManagerDelegates.set(owner, delegate); | ||
} | ||
|
||
return delegate; | ||
} | ||
|
||
getDelegateFor(owner: any | undefined) { | ||
if (owner === undefined) { | ||
let { undefinedDelegate } = this; | ||
|
||
if (undefinedDelegate === null) { | ||
let { factory } = this; | ||
this.undefinedDelegate = undefinedDelegate = factory(undefined); | ||
} | ||
|
||
return undefinedDelegate; | ||
} else { | ||
return this.getDelegateForOwner(owner); | ||
} | ||
} | ||
|
||
getHelper(definition: any): any { | ||
return (capturedArgs, owner) => { | ||
let manager = this.getDelegateFor(owner as any | undefined); | ||
|
||
const args = argsProxyFor(capturedArgs, 'helper'); | ||
const bucket = manager.createHelper(definition, args); | ||
|
||
return () => { | ||
return manager.getValue(bucket); | ||
}; | ||
}; | ||
} | ||
} |
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
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