-
-
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.
Merge pull request #17803 from emberjs/input-manager
- Loading branch information
Showing
17 changed files
with
348 additions
and
214 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
93 changes: 93 additions & 0 deletions
93
packages/@ember/-internals/glimmer/lib/component-managers/input.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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { set } from '@ember/-internals/metal'; | ||
import { Owner } from '@ember/-internals/owner'; | ||
import { assert, debugFreeze } from '@ember/debug'; | ||
import { ComponentCapabilities, Dict } from '@glimmer/interfaces'; | ||
import { CONSTANT_TAG, isConst, VersionedPathReference } from '@glimmer/reference'; | ||
import { Arguments, DynamicScope, Environment, PreparedArguments } from '@glimmer/runtime'; | ||
import { Destroyable } from '@glimmer/util'; | ||
import { RootReference } from '../utils/references'; | ||
import InternalComponentManager, { InternalDefinitionState } from './internal'; | ||
|
||
const CAPABILITIES: ComponentCapabilities = { | ||
dynamicLayout: false, | ||
dynamicTag: false, | ||
prepareArgs: true, | ||
createArgs: true, | ||
attributeHook: false, | ||
elementHook: false, | ||
createCaller: true, | ||
dynamicScope: false, | ||
updateHook: true, | ||
createInstance: false, | ||
}; | ||
|
||
export interface InputComponentState { | ||
type: VersionedPathReference; | ||
instance: Destroyable; | ||
} | ||
|
||
const EMPTY_POSITIONAL_ARGS: VersionedPathReference[] = []; | ||
|
||
debugFreeze(EMPTY_POSITIONAL_ARGS); | ||
|
||
export default class InputComponentManager extends InternalComponentManager<InputComponentState> { | ||
getCapabilities(): ComponentCapabilities { | ||
return CAPABILITIES; | ||
} | ||
|
||
prepareArgs(_state: InternalDefinitionState, args: Arguments): PreparedArguments { | ||
assert( | ||
'The `<Input />` component does not take any positional arguments', | ||
args.positional.length === 0 | ||
); | ||
|
||
let __ARGS__: Dict<VersionedPathReference> = args.named.capture().map; | ||
|
||
return { | ||
positional: EMPTY_POSITIONAL_ARGS, | ||
named: { | ||
__ARGS__: new RootReference(__ARGS__), | ||
type: args.named.get('type'), | ||
}, | ||
}; | ||
} | ||
|
||
create( | ||
_env: Environment, | ||
{ ComponentClass }: InternalDefinitionState, | ||
args: Arguments, | ||
_dynamicScope: DynamicScope, | ||
caller: VersionedPathReference | ||
): InputComponentState { | ||
assert('caller must be const', isConst(caller)); | ||
|
||
let type = args.named.get('type'); | ||
|
||
let instance = ComponentClass.create({ | ||
caller: caller.value(), | ||
type: type.value(), | ||
}); | ||
|
||
return { type, instance }; | ||
} | ||
|
||
getSelf({ instance }: InputComponentState): VersionedPathReference { | ||
return new RootReference(instance); | ||
} | ||
|
||
getTag() { | ||
return CONSTANT_TAG; | ||
} | ||
|
||
update({ type, instance }: InputComponentState): void { | ||
set(instance, 'type', type.value()); | ||
} | ||
|
||
getDestructor({ instance }: InputComponentState): Destroyable { | ||
return instance; | ||
} | ||
} | ||
|
||
export const InputComponentManagerFactory = (owner: Owner) => { | ||
return new InputComponentManager(owner); | ||
}; |
41 changes: 41 additions & 0 deletions
41
packages/@ember/-internals/glimmer/lib/component-managers/internal.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Factory, Owner } from '@ember/-internals/owner'; | ||
import { OwnedTemplateMeta } from '@ember/-internals/views'; | ||
import { ComponentDefinition, Invocation, WithStaticLayout } from '@glimmer/runtime'; | ||
import RuntimeResolver from '../resolver'; | ||
import { OwnedTemplate } from '../template'; | ||
import AbstractComponentManager from './abstract'; | ||
|
||
export interface InternalDefinitionState { | ||
ComponentClass: Factory<any, any>; | ||
layout: OwnedTemplate; | ||
} | ||
|
||
export class InternalComponentDefinition<T> | ||
implements ComponentDefinition<InternalDefinitionState, InternalManager<T>> { | ||
public state: InternalDefinitionState; | ||
|
||
constructor( | ||
public manager: InternalManager<T>, | ||
ComponentClass: Factory<any, any>, | ||
layout: OwnedTemplate | ||
) { | ||
this.state = { ComponentClass, layout }; | ||
} | ||
} | ||
|
||
export default abstract class InternalManager<T> | ||
extends AbstractComponentManager<T, InternalDefinitionState> | ||
implements WithStaticLayout<T, InternalDefinitionState, OwnedTemplateMeta, RuntimeResolver> { | ||
constructor(protected owner: Owner) { | ||
super(); | ||
} | ||
|
||
getLayout({ layout: _layout }: InternalDefinitionState): Invocation { | ||
let layout = _layout.asLayout(); | ||
|
||
return { | ||
handle: layout.compile(), | ||
symbolTable: layout.symbolTable, | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.