-
-
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 #17710 from emberjs/bugfix/allow-accessors-in-mixins
[BUGFIX beta] Allow accessors in mixins
- Loading branch information
Showing
4 changed files
with
89 additions
and
2 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
38 changes: 38 additions & 0 deletions
38
packages/@ember/-internals/metal/tests/mixin/accessor_test.js
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,38 @@ | ||
import { Mixin } from '../..'; | ||
import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; | ||
|
||
moduleFor( | ||
'Mixin Accessors', | ||
class extends AbstractTestCase { | ||
['@test works with getters'](assert) { | ||
let count = 0; | ||
|
||
let MixinA = Mixin.create({ | ||
get prop() { | ||
return count++; | ||
}, | ||
}); | ||
|
||
let obj = {}; | ||
MixinA.apply(obj); | ||
|
||
assert.equal(obj.prop, 0, 'getter defined correctly'); | ||
assert.equal(obj.prop, 1, 'getter defined correctly'); | ||
} | ||
|
||
['@test works with setters'](assert) { | ||
let MixinA = Mixin.create({ | ||
set prop(value) { | ||
this._prop = value + 1; | ||
}, | ||
}); | ||
|
||
let obj = {}; | ||
MixinA.apply(obj); | ||
|
||
obj.prop = 0; | ||
|
||
assert.equal(obj._prop, 1, 'setter defined correctly'); | ||
} | ||
} | ||
); |
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
17 changes: 17 additions & 0 deletions
17
packages/@ember/-internals/utils/lib/get-own-property-descriptors.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,17 @@ | ||
let getOwnPropertyDescriptors: (obj: { [x: string]: any }) => { [x: string]: PropertyDescriptor }; | ||
|
||
if (Object.getOwnPropertyDescriptors !== undefined) { | ||
getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors; | ||
} else { | ||
getOwnPropertyDescriptors = function(obj: object) { | ||
let descriptors = {}; | ||
|
||
Object.keys(obj).forEach(key => { | ||
descriptors[key] = Object.getOwnPropertyDescriptor(obj, key); | ||
}); | ||
|
||
return descriptors; | ||
}; | ||
} | ||
|
||
export default getOwnPropertyDescriptors; |