File tree Expand file tree Collapse file tree 4 files changed +10
-30
lines changed Expand file tree Collapse file tree 4 files changed +10
-30
lines changed Original file line number Diff line number Diff line change @@ -10,18 +10,18 @@ function destroyModifier(modifier: ClassBasedModifier): void {
10
10
modifier . willDestroy ( ) ;
11
11
}
12
12
13
- class ClassBasedModifierManager {
13
+ export default class ClassBasedModifierManager {
14
14
capabilities = capabilities ( '3.13' ) ;
15
15
16
+ constructor ( private owner : unknown ) { }
17
+
16
18
createModifier (
17
19
factory : { owner : unknown ; class : typeof ClassBasedModifier } ,
18
20
args : ModifierArgs
19
21
) : ClassBasedModifier {
20
- // TODO: stop getting the owner off the factory like this; it is *not* per
21
- // the spec. See https://github.com/ember-modifier/ember-modifier/issues/25
22
- const { owner, class : Modifier } = factory ;
22
+ const Modifier = factory . class ;
23
23
24
- const modifier = new Modifier ( owner , args ) ;
24
+ const modifier = new Modifier ( this . owner , args ) ;
25
25
26
26
registerDestructor ( modifier , destroyModifier ) ;
27
27
@@ -45,5 +45,3 @@ class ClassBasedModifierManager {
45
45
destroy ( instance ) ;
46
46
}
47
47
}
48
-
49
- export default new ClassBasedModifierManager ( ) ;
Original file line number Diff line number Diff line change @@ -97,4 +97,4 @@ export default class ClassBasedModifier<
97
97
}
98
98
}
99
99
100
- setModifierManager ( ( ) => Manager , ClassBasedModifier ) ;
100
+ setModifierManager ( ( owner ) => new Manager ( owner ) , ClassBasedModifier ) ;
Original file line number Diff line number Diff line change @@ -28,15 +28,9 @@ function setup(
28
28
MODIFIER_TEARDOWNS . set ( modifier , teardown ) ;
29
29
}
30
30
31
- export default class FunctionalModifierManager {
31
+ class FunctionalModifierManager {
32
32
capabilities = capabilities ( '3.13' ) ;
33
33
34
- // TODO: remove this entirely as part of #25
35
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
- constructor ( _owner : unknown ) {
37
- /* no-op */
38
- }
39
-
40
34
createModifier ( factory : Factory ) : FunctionalModifier {
41
35
// This looks superfluous, but this is creating a new instance
42
36
// of a function -- this is important so that each instance of the
@@ -65,3 +59,5 @@ export default class FunctionalModifierManager {
65
59
teardown ( modifier ) ;
66
60
}
67
61
}
62
+
63
+ export default new FunctionalModifierManager ( ) ;
Original file line number Diff line number Diff line change @@ -7,20 +7,6 @@ export type FunctionalModifier<
7
7
N extends ModifierArgs [ 'named' ] = ModifierArgs [ 'named' ]
8
8
> = ( element : Element , positional : P , named : N ) => unknown ;
9
9
10
- const MANAGERS : WeakMap < object , FunctionalModifierManager > = new WeakMap ( ) ;
11
-
12
- function managerFor ( owner : object ) : FunctionalModifierManager {
13
- let manager = MANAGERS . get ( owner ) ;
14
-
15
- if ( manager === undefined ) {
16
- manager = new FunctionalModifierManager ( owner ) ;
17
- }
18
-
19
- return manager ;
20
- }
21
-
22
- // TODO: simplify this -- it doesn't (and shouldn't) use the owner at all.
23
- // See https://github.com/ember-modifier/ember-modifier/issues/26
24
10
/**
25
11
* An API for writing simple modifiers.
26
12
*
@@ -37,5 +23,5 @@ function managerFor(owner: object): FunctionalModifierManager {
37
23
* @param fn The function which defines the modifier.
38
24
*/
39
25
export default function modifier ( fn : FunctionalModifier ) : unknown {
40
- return setModifierManager ( managerFor , fn ) ;
26
+ return setModifierManager ( ( ) => FunctionalModifierManager , fn ) ;
41
27
}
You can’t perform that action at this time.
0 commit comments