Skip to content

Commit

Permalink
refactor(all): fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanrsmith committed Aug 9, 2015
1 parent 95fdefa commit ccd8cf4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 70 deletions.
28 changes: 13 additions & 15 deletions src/decorator-applicator.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
export class DecoratorApplicator {
constructor(){
constructor() {
this._first = null;
this._second = null;
this._third = null;
this._rest = null;
}

decorator(decorator:Function):DecoratorApplicator{
if(this._first === null){
decorator(decorator: Function): DecoratorApplicator {
if (this._first === null) {
this._first = decorator;
return this;
}

if(this._second === null){
if (this._second === null) {
this._second = decorator;
return this;
}

if(this._third === null){
if (this._third === null) {
this._third = decorator;
return this;
}

if(this._rest === null){
if (this._rest === null) {
this._rest = [];
}

Expand All @@ -31,24 +31,22 @@ export class DecoratorApplicator {
return this;
}

_decorate(target:Function){
var i, ii, rest;

if(this._first !== null){
_decorate(target: Function) {
if (this._first !== null) {
this._first(target);
}

if(this._second !== null){
if (this._second !== null) {
this._second(target);
}

if(this._third !== null){
if (this._third !== null) {
this._third(target);
}

rest = this._rest;
if(rest !== null){
for(i = 0, ii = rest.length; i < ii; ++i){
let rest = this._rest;
if (rest !== null) {
for (let i = 0, ii = rest.length; i < ii; ++i) {
rest[i](target);
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/decorators.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {DecoratorApplicator} from './decorator-applicator';

export var Decorators = {
export const Decorators = {
configure: {
parameterizedDecorator(name:string, decorator:Function){
Decorators[name] = function(){
var applicator = new DecoratorApplicator();
parameterizedDecorator(name: string, decorator: Function) {
Decorators[name] = function() {
let applicator = new DecoratorApplicator();
return applicator[name].apply(applicator, arguments);
};

DecoratorApplicator.prototype[name] = function(){
var result = decorator.apply(null, arguments);
DecoratorApplicator.prototype[name] = function() {
let result = decorator.apply(null, arguments);
return this.decorator(result);
};
},
simpleDecorator(name:string, decorator:Function){
Decorators[name] = function(){
simpleDecorator(name: string, decorator: Function) {
Decorators[name] = function() {
return new DecoratorApplicator().decorator(decorator);
};

DecoratorApplicator.prototype[name] = function(){
DecoratorApplicator.prototype[name] = function() {
return this.decorator(decorator);
}
};
}
}
}
};
66 changes: 33 additions & 33 deletions src/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,53 @@ const theGlobal = (function() {
const emptyMetadata = Object.freeze({});
const metadataContainerKey = '__metadata__';

if(typeof theGlobal.System === 'undefined'){
theGlobal.System = { isFake:true };
if (typeof theGlobal.System === 'undefined') {
theGlobal.System = {isFake: true};
}

if(typeof theGlobal.System.forEachModule === 'undefined'){
theGlobal.System.forEachModule = function(){};
if (typeof theGlobal.System.forEachModule === 'undefined') {
theGlobal.System.forEachModule = function() {};
}

if(typeof theGlobal.Reflect === 'undefined'){
if (typeof theGlobal.Reflect === 'undefined') {
theGlobal.Reflect = {};
}

if(typeof theGlobal.Reflect.getOwnMetadata === 'undefined'){
Reflect.getOwnMetadata = function(metadataKey, target, targetKey){
if (typeof theGlobal.Reflect.getOwnMetadata === 'undefined') {
Reflect.getOwnMetadata = function(metadataKey, target, targetKey) {
return ((target[metadataContainerKey] || emptyMetadata)[targetKey] || emptyMetadata)[metadataKey];
};
}

if(typeof theGlobal.Reflect.defineMetadata === 'undefined'){
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey){
var metadataContainer = target[metadataContainerKey] || (target[metadataContainerKey] = {});
var targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
if (typeof theGlobal.Reflect.defineMetadata === 'undefined') {
Reflect.defineMetadata = function(metadataKey, metadataValue, target, targetKey) {
let metadataContainer = target[metadataContainerKey] || (target[metadataContainerKey] = {});
let targetContainer = metadataContainer[targetKey] || (metadataContainer[targetKey] = {});
targetContainer[metadataKey] = metadataValue;
};
}

if(typeof theGlobal.Reflect.metadata === 'undefined'){
Reflect.metadata = function(metadataKey, metadataValue){
return function(target, targetKey){
if (typeof theGlobal.Reflect.metadata === 'undefined') {
Reflect.metadata = function(metadataKey, metadataValue) {
return function(target, targetKey) {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);
};
};
}

function ensureDecorators(target){
var applicator;
function ensureDecorators(target) {
let applicator;

if(typeof target.decorators === 'function'){
if (typeof target.decorators === 'function') {
applicator = target.decorators();
}else{
} else {
applicator = target.decorators;
}

if(typeof applicator._decorate === 'function'){
if (typeof applicator._decorate === 'function') {
delete target.decorators;
applicator._decorate(target);
}else{
} else {
throw new Error('The return value of your decorator\'s method was not valid.');
}
}
Expand All @@ -73,41 +73,41 @@ function ensureDecorators(target){
* @class Metadata
* @static
*/
export var Metadata = {
export const Metadata = {
global: theGlobal,
resource:'aurelia:resource',
paramTypes:'design:paramtypes',
properties:'design:properties',
get(metadataKey:string, target:Function, targetKey:string){
if(!target){
resource: 'aurelia:resource',
paramTypes: 'design:paramtypes',
properties: 'design:properties',
get(metadataKey: string, target: Function, targetKey: string) {
if (!target) {
return undefined;
}

let result = Metadata.getOwn(metadataKey, target, targetKey);
return result === undefined ? Metadata.get(metadataKey, Object.getPrototypeOf(target), targetKey) : result;
},
getOwn(metadataKey:string, target:Function, targetKey:string){
if(!target){
getOwn(metadataKey: string, target: Function, targetKey: string) {
if (!target) {
return undefined;
}

if(target.hasOwnProperty('decorators')){
if (target.hasOwnProperty('decorators')) {
ensureDecorators(target);
}

return Reflect.getOwnMetadata(metadataKey, target, targetKey);
},
define(metadataKey:string, metadataValue:string, target:Function, targetKey:string){
define(metadataKey: string, metadataValue: string, target: Function, targetKey: string) {
Reflect.defineMetadata(metadataKey, metadataValue, target, targetKey);
},
getOrCreateOwn(metadataKey:string, Type:Function, target:Function, targetKey:string){
getOrCreateOwn(metadataKey: string, Type: Function, target: Function, targetKey: string) {
let result = Metadata.getOwn(metadataKey, target, targetKey);

if(result === undefined){
if (result === undefined) {
result = new Type();
Reflect.defineMetadata(metadataKey, result, target, targetKey);
}

return result;
}
}
};
22 changes: 11 additions & 11 deletions src/origin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import core from 'core-js';

var originStorage = new Map(),
unknownOrigin = Object.freeze({moduleId:undefined,moduleMember:undefined});
let originStorage = new Map();
let unknownOrigin = Object.freeze({moduleId: undefined, moduleMember: undefined});

/**
* A metadata annotation that describes the origin module of the function to which it's attached.
Expand All @@ -12,7 +12,7 @@ var originStorage = new Map(),
* @param {string} moduleMember The name of the export in the origin module.
*/
export class Origin {
constructor(moduleId:string, moduleMember:string){
constructor(moduleId: string, moduleMember: string) {
this.moduleId = moduleId;
this.moduleMember = moduleMember;
}
Expand All @@ -25,20 +25,20 @@ export class Origin {
* @param {Function} fn The function to inspect for Origin metadata.
* @return {Origin} Returns the Origin metadata.
*/
static get(fn:Function){
var origin = originStorage.get(fn);
static get(fn: Function) {
let origin = originStorage.get(fn);

if(origin === undefined){
if (origin === undefined) {
System.forEachModule((key, value) => {
for(var name in value){
var exp = value[name];
if(exp === fn){
for (let name in value) {
let exp = value[name];
if (exp === fn) {
originStorage.set(fn, origin = new Origin(key, name));
return true;
}
}

if(value === fn){
if (value === fn) {
originStorage.set(fn, origin = new Origin(key, 'default'));
return true;
}
Expand All @@ -57,7 +57,7 @@ export class Origin {
* @param {origin} fn The Origin metadata to store on the function.
* @return {Origin} Returns the Origin metadata.
*/
static set(fn:Function, origin:Origin){
static set(fn: Function, origin: Origin) {
originStorage.set(fn, origin);
}
}

0 comments on commit ccd8cf4

Please sign in to comment.