-
-
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.
Share more stuff between custom managers
- Loading branch information
1 parent
64eadfe
commit 772e868
Showing
6 changed files
with
78 additions
and
87 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
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
33 changes: 15 additions & 18 deletions
33
packages/@ember/-internals/glimmer/lib/utils/custom-component-manager.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,27 +1,24 @@ | ||
import { Owner } from '@ember/-internals/owner'; | ||
import { GLIMMER_CUSTOM_COMPONENT_MANAGER } from '@ember/canary-features'; | ||
import { Opaque } from '@glimmer/interfaces'; | ||
import { getManager, ManagerFactory, setManager } from './managers'; | ||
|
||
const getPrototypeOf = Object.getPrototypeOf; | ||
const MANAGERS: WeakMap<any, string> = new WeakMap(); | ||
|
||
export function setComponentManager(managerId: string, obj: any) { | ||
MANAGERS.set(obj, managerId); | ||
|
||
return obj; | ||
export function setComponentManager(stringOrFunction: string | ManagerFactory<Opaque>, obj: any) { | ||
let factory; | ||
if (typeof stringOrFunction === 'string') { | ||
factory = function(owner: Owner) { | ||
return owner.lookup(`component-manager:${stringOrFunction}`); | ||
}; | ||
} else { | ||
factory = stringOrFunction; | ||
} | ||
return setManager(factory, obj); | ||
} | ||
|
||
export function getComponentManager(obj: any): string | undefined { | ||
export function getComponentManager<T>(obj: any): undefined | ManagerFactory<T> { | ||
if (!GLIMMER_CUSTOM_COMPONENT_MANAGER) { | ||
return; | ||
} | ||
|
||
let pointer = obj; | ||
while (pointer !== undefined && pointer !== null) { | ||
if (MANAGERS.has(pointer)) { | ||
return MANAGERS.get(pointer); | ||
} | ||
|
||
pointer = getPrototypeOf(pointer); | ||
} | ||
|
||
return; | ||
return getManager(obj); | ||
} |
27 changes: 5 additions & 22 deletions
27
packages/@ember/-internals/glimmer/lib/utils/custom-modifier-manager.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,32 +1,15 @@ | ||
import { Owner } from '@ember/-internals/owner'; | ||
import { GLIMMER_MODIFIER_MANAGER } from '@ember/canary-features'; | ||
import { Opaque } from '@glimmer/util'; | ||
import { ModifierManagerDelegate } from '../modifiers/custom'; | ||
import { getManager, ManagerFactory, setManager } from './managers'; | ||
|
||
const getPrototypeOf = Object.getPrototypeOf; | ||
|
||
export type ModifierManagerFactory = (owner: Owner) => ModifierManagerDelegate<Opaque>; | ||
|
||
const MANAGERS: WeakMap<any, ModifierManagerFactory> = new WeakMap(); | ||
|
||
export function setModifierManager(factory: ModifierManagerFactory, obj: any) { | ||
MANAGERS.set(obj, factory); | ||
return obj; | ||
export function setModifierManager(factory: ManagerFactory<Opaque>, obj: any) { | ||
return setManager(factory, obj); | ||
} | ||
|
||
export function getModifierManager(obj: any): undefined | ModifierManagerFactory { | ||
export function getModifierManager<T>(obj: any): undefined | ManagerFactory<T> { | ||
if (!GLIMMER_MODIFIER_MANAGER) { | ||
return; | ||
} | ||
|
||
let pointer = obj; | ||
while (pointer !== undefined && pointer !== null) { | ||
if (MANAGERS.has(pointer)) { | ||
return MANAGERS.get(pointer); | ||
} | ||
|
||
pointer = getPrototypeOf(pointer); | ||
} | ||
|
||
return; | ||
return getManager(obj); | ||
} |
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,39 @@ | ||
import { Owner } from '@ember/-internals/owner'; | ||
import { Dict, Opaque } from '@glimmer/interfaces'; | ||
import { CapturedArguments } from '@glimmer/runtime'; | ||
|
||
const MANAGERS: WeakMap<any, ManagerFactory<Opaque>> = new WeakMap(); | ||
|
||
const getPrototypeOf = Object.getPrototypeOf; | ||
|
||
export type ManagerFactory<ManagerDelegate> = (owner: Owner) => ManagerDelegate; | ||
|
||
export function setManager<ManagerDelegate>(factory: ManagerFactory<ManagerDelegate>, obj: any) { | ||
MANAGERS.set(obj, factory); | ||
return obj; | ||
} | ||
|
||
export function getManager<T>(obj: any): undefined | ManagerFactory<T> { | ||
let pointer = obj; | ||
while (pointer !== undefined && pointer !== null) { | ||
if (MANAGERS.has(pointer)) { | ||
return MANAGERS.get(pointer) as ManagerFactory<T>; | ||
} | ||
|
||
pointer = getPrototypeOf(pointer); | ||
} | ||
|
||
return; | ||
} | ||
|
||
export function valueForCapturedArgs(args: CapturedArguments): ManagerArgs { | ||
return { | ||
named: args.named.value(), | ||
positional: args.positional.value(), | ||
}; | ||
} | ||
|
||
export interface ManagerArgs { | ||
named: Dict<Opaque>; | ||
positional: Opaque[]; | ||
} |