Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Dec 7, 2018
1 parent fbedc41 commit 0f46f75
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 241 deletions.
2 changes: 0 additions & 2 deletions packages/@ember/-internals/metal/lib/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { EMBER_METAL_TRACKED_PROPERTIES } from '@ember/canary-features';
import { assert, warn } from '@ember/debug';
import EmberError from '@ember/error';

import { computedDecoratorWithParams } from './decorator-utils/index';

import {
getCachedValueFor,
getCacheFor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import { DEBUG } from '@glimmer/env';

import { assert } from '@ember/debug';

const DESCRIPTOR = '__DESCRIPTOR__';

function isCPGetter(getter: any) {
// Hack for descriptor traps, we want to be able to tell if the function
// is a descriptor trap before we call it at all
return getter !== null && typeof getter === 'function' && getter.toString().indexOf('CPGETTER_FUNCTION') !== -1;
}

function isDescriptorTrap(possibleDesc: any) {
throw new Error('Cannot call `isDescriptorTrap` in production');
}

export function isComputedDescriptor(possibleDesc: any) {
return possibleDesc !== null && typeof possibleDesc === 'object' && possibleDesc.isDescriptor;
}
Expand All @@ -23,7 +9,7 @@ export function computedDescriptorFor(obj: any, keyName: any) {
assert('Cannot call `descriptorFor` on undefined', obj !== undefined);
assert(`Cannot call \`descriptorFor\` on ${typeof obj}`, typeof obj === 'object' || typeof obj === 'function');

let { value: possibleDesc, get: possibleCPGetter } = Object.getOwnPropertyDescriptor(obj, keyName);
let { value: possibleDesc } = Object.getOwnPropertyDescriptor(obj, keyName);

return isComputedDescriptor(possibleDesc) ? possibleDesc : undefined;
return isComputedDescriptor(possibleDesc) ? possibleDesc : undefined;
}

This file was deleted.

77 changes: 1 addition & 76 deletions packages/@ember/-internals/metal/lib/decorator-utils/computed.ts
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);
}
135 changes: 1 addition & 134 deletions packages/@ember/-internals/metal/lib/decorator-utils/decorator.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,15 @@
import { assert } from '@ember/debug';

// import { NEEDS_STAGE_1_DECORATORS } from 'ember-decorators-flags';

function isDescriptor(possibleDesc) {
let isDescriptor = isStage2Descriptor(possibleDesc);

// if (NEEDS_STAGE_1_DECORATORS) {
// isDescriptor = isDescriptor || isStage1Descriptor(possibleDesc);
// }

return isDescriptor;
}

// function isStage1Descriptor(possibleDesc) {
// if (possibleDesc.length === 3) {
// let [target, key, desc] = possibleDesc;

// return typeof target === 'object'
// && target !== null
// && typeof key === 'string'
// && (
// (
// typeof desc === 'object'
// && desc !== null
// && 'enumerable' in desc
// && 'configurable' in desc
// )
// || desc === undefined // TS compatibility
// );
// } else if (possibleDesc.length === 1) {
// let [target] = possibleDesc;

// return typeof target === 'function' && 'prototype' in target;
// }

// return false;
// }

function isStage2Descriptor(possibleDesc) {
return possibleDesc && possibleDesc.toString() === '[object Descriptor]';
}

function kindForDesc(desc) {
if ('value' in desc && desc.enumerable === true) {
return 'field';
} else {
return 'method';
}
}

function placementForKind(kind) {
return kind === 'method' ? 'prototype' : 'own';
}

// function convertStage1ToStage2(desc) {
// if (desc.length === 3) {
// // Class element decorator
// let [, key, descriptor] = desc;

// let kind = kindForDesc(desc);
// let placement = placementForKind(kind);

// let initializer = descriptor !== undefined ? descriptor.initializer : undefined;

// return {
// descriptor,
// key,
// kind,
// placement,
// initializer,
// toString: () => '[object Descriptor]',
// };
// } else {
// // Class decorator
// return {
// kind: 'class',
// elements: [],
// };
// }
// }

export function decorator(fn) {
// if (NEEDS_STAGE_1_DECORATORS) {
// return function(...params) {
// if (isStage2Descriptor(params)) {
// let desc = params[0];

// return fn(desc);
// } else {
// let desc = convertStage1ToStage2(params);

// fn(desc);

// if (typeof desc.finisher === 'function') {
// // Finishers are supposed to run at the end of class finalization,
// // but we don't get that with stage 1 transforms. We have to be careful
// // to make sure that we aren't doing any operations which would change
// // due to timing.
// let [target] = params;

// desc.finisher(target.prototype ? target : target.constructor);
// }

// if (typeof desc.initializer === 'function') {
// // Babel 6 / the legacy decorator transform needs the initializer back
// // on the property descriptor/ In case the user has set a new
// // initializer on the member descriptor, we transfer it back to
// // original descriptor.
// desc.descriptor.initializer = desc.initializer;
// }

// return desc.descriptor;
// }
// }
// } else {
return fn;
// }
return fn;
}

/**
Expand Down Expand Up @@ -145,30 +39,3 @@ export function decoratorWithParams(fn) {
}
};
}

/**
* A macro that takes a decorator function and requires it to receive
* parameters:
*
* ```js
* let foo = decoratorWithRequiredParams((target, desc, key, params) => {
* console.log(params);
* });
*
* class {
* @foo('bar') baz; // ['bar']
* @foo bar; // Error
* }
* ```
*
* @param {Function} fn - decorator function
*/
export function decoratorWithRequiredParams(fn, name) {
return function(...params) {
assert(`The @${name || fn.name} decorator requires parameters`, !isDescriptor(params) && params.length > 0);

return decorator(desc => {
return fn(desc, params);
});
}
}
5 changes: 0 additions & 5 deletions packages/@ember/-internals/metal/lib/decorator-utils/index.ts

This file was deleted.

0 comments on commit 0f46f75

Please sign in to comment.