-
-
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
1 parent
fbedc41
commit 0f46f75
Showing
6 changed files
with
4 additions
and
241 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
8 changes: 0 additions & 8 deletions
8
packages/@ember/-internals/metal/lib/decorator-utils/collapse-proto.ts
This file was deleted.
Oops, something went wrong.
77 changes: 1 addition & 76 deletions
77
packages/@ember/-internals/metal/lib/decorator-utils/computed.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,80 +1,5 @@ | ||
// import { defineProperty } from '@ember/object'; | ||
import { decoratorWithParams, decoratorWithRequiredParams, decorator } from './decorator'; | ||
// import { HAS_NATIVE_COMPUTED_GETTERS } from 'ember-compatibility-helpers'; | ||
// import { NEEDS_STAGE_1_DECORATORS } from 'ember-decorators-flags'; | ||
|
||
import { computedDescriptorFor, isComputedDescriptor } from './-private/descriptor'; | ||
import { computedDescriptorFor } from './-private/descriptor'; | ||
import { getModifierMeta, getOrCreateModifierMeta } from './-private/modifier-meta'; | ||
|
||
import { assert } from '@ember/debug'; | ||
|
||
export { computedDescriptorFor, getModifierMeta, getOrCreateModifierMeta }; | ||
|
||
/** | ||
* A macro that receives a decorator function which returns a ComputedProperty, | ||
* and defines that property using `Ember.defineProperty`. Conceptually, CPs | ||
* are custom property descriptors that require Ember's intervention to apply | ||
* correctly. In the future, we will use finishers to define the CPs rather than | ||
* directly defining them in the decorator function. | ||
* | ||
* @param {Function} fn - decorator function | ||
*/ | ||
function computedDecoratorInner(fn) { | ||
return (desc, params = []) => { | ||
// All computeds are methods | ||
desc.kind = 'method'; | ||
desc.placement = 'prototype'; | ||
|
||
desc.finisher = function initializeComputedProperty(target) { | ||
let { prototype } = target; | ||
let { key } = desc; | ||
|
||
assert(`ES6 property getters/setters only need to be decorated once, '${key}' was decorated on both the getter and the setter`, !computedDescriptorFor(prototype, key)); | ||
|
||
let computedDesc = fn(desc, params); | ||
|
||
assert(`computed decorators must return an instance of an Ember ComputedProperty descriptor, received ${computedDesc}`, isComputedDescriptor(computedDesc)); | ||
|
||
let modifierMeta = getModifierMeta(prototype); | ||
|
||
if (modifierMeta !== undefined && modifierMeta[key] !== undefined) { | ||
computedDesc[modifierMeta[key]](); | ||
} | ||
|
||
// if (!HAS_NATIVE_COMPUTED_GETTERS) { | ||
// // Until recent versions of Ember, computed properties would be defined | ||
// // by just setting them. We need to blow away any predefined properties | ||
// // (getters/setters, etc.) to allow Ember.defineProperty to work correctly. | ||
// Object.defineProperty(prototype, key, { | ||
// configurable: true, | ||
// writable: true, | ||
// enumerable: true, | ||
// value: undefined | ||
// }); | ||
// } | ||
|
||
// defineProperty(prototype, key, computedDesc); | ||
Object.defineProperty(prototype, key, computedDesc); | ||
|
||
// if (NEEDS_STAGE_1_DECORATORS) { | ||
// // There's currently no way to disable redefining the property when decorators | ||
// // are run, so return the property descriptor we just assigned | ||
// desc.descriptor = Object.getOwnPropertyDescriptor(prototype, key); | ||
// } | ||
|
||
return target; | ||
} | ||
} | ||
} | ||
|
||
export function computedDecorator(fn) { | ||
return decorator(computedDecoratorInner(fn)); | ||
} | ||
|
||
export function computedDecoratorWithParams(fn) { | ||
return decoratorWithParams(computedDecoratorInner(fn)); | ||
} | ||
|
||
export function computedDecoratorWithRequiredParams(fn, name) { | ||
return decoratorWithRequiredParams(computedDecoratorInner(fn), name); | ||
} |
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
5 changes: 0 additions & 5 deletions
5
packages/@ember/-internals/metal/lib/decorator-utils/index.ts
This file was deleted.
Oops, something went wrong.