Skip to content

Commit

Permalink
feat(*): add support for Angular 2+ in AOT mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 committed Aug 5, 2017
1 parent 8c63692 commit d0a602d
Show file tree
Hide file tree
Showing 34 changed files with 273 additions and 122 deletions.
13 changes: 9 additions & 4 deletions src/after.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import after = require('lodash/after');

import { DecoratorConfig, DecoratorFactory, LodashDecorator } from './factory';
import { PostValueApplicator } from './applicators';

const decorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(after, new PostValueApplicator(), { setter: true })
);

/**
* The opposite of Before. This method creates a function that invokes once it's called n or more times.
* @param {number} n The number of calls before the function is invoked.
Expand All @@ -19,8 +24,8 @@ import { PostValueApplicator } from './applicators';
* myClass.fn(); // => undefined
* myClass.fn(); // => 10
*/
export const After: (n: number) => LodashDecorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(after, new PostValueApplicator(), { setter: true })
);
export function After(n: number): LodashDecorator {
return decorator(n);
}
export { After as after };
export default After;
export default decorator;
13 changes: 9 additions & 4 deletions src/afterAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import after = require('lodash/after');

import { DecoratorConfig, DecoratorFactory, LodashDecorator } from './factory';
import { PostValueApplicator } from './applicators';

const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(after, new PostValueApplicator(), { setter: true })
);

/**
* The opposite of Before. This method creates a function that invokes once it's called n or more times.
* This spans across all instances of the class instead of the instance.
Expand All @@ -24,8 +29,8 @@ import { PostValueApplicator } from './applicators';
* myClass2.fn(); // => 10
* myClass2.fn(); // => 10
*/
export const AfterAll: (n: number) => LodashDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(after, new PostValueApplicator(), { setter: true })
);
export function AfterAll(n: number): LodashDecorator {
return decorator(n);
}
export { AfterAll as afterAll };
export default AfterAll;
export default decorator;
13 changes: 9 additions & 4 deletions src/ary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import ary = require('lodash/ary');

import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';

const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(ary, new PreValueApplicator())
);

/**
* Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
* @param {number} n The arity cap.
Expand All @@ -18,8 +23,8 @@ import { PreValueApplicator } from './applicators';
*
* myClass.fn(1, 2, 3, 4); // => [ 1 ]
*/
export const Ary: (n: number) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(ary, new PreValueApplicator())
);
export function Ary(n: number): LodashMethodDecorator {
return decorator(n);
}
export { Ary as ary };
export default Ary;
export default decorator;
12 changes: 8 additions & 4 deletions src/attempt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './fact
import { PreValueApplicator } from './applicators';

const attemptFn = (fn: () => void) => partial(attempt, fn);
const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(attemptFn, new PreValueApplicator())
);

/**
* Attempts to invoke func, returning either the result or the caught error object. Any additional arguments are provided to func when it's invoked.
* @param {...*} [args] The arguments to invoke func with.
Expand All @@ -26,8 +30,8 @@ const attemptFn = (fn: () => void) => partial(attempt, fn);
* myClass.fn(10); // => 10;
* myClass.fn(null); // => Error
*/
export const Attempt: (...partials: any[]) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(attemptFn, new PreValueApplicator())
);
export function Attempt(...partials: any[]): LodashMethodDecorator {
return decorator(...partials);
}
export { Attempt as attempt };
export default Attempt;
export default decorator;
13 changes: 9 additions & 4 deletions src/before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import before = require('lodash/before');

import { DecoratorConfig, DecoratorFactory, LodashDecorator } from './factory';
import { PostValueApplicator } from './applicators';

const decorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(before, new PostValueApplicator(), { setter: true })
);

/**
* Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times.
* Subsequent calls to the created function return the result of the last func invocation.
Expand All @@ -26,8 +31,8 @@ import { PostValueApplicator } from './applicators';
*
* calls === 2; // => true
*/
export const Before: (n: number) => LodashDecorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(before, new PostValueApplicator(), { setter: true })
);
export function Before(n: number): LodashDecorator {
return decorator(n);
}
export { Before as before };
export default Before;
export default decorator;
13 changes: 9 additions & 4 deletions src/beforeAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import before = require('lodash/before');

import { DecoratorConfig, DecoratorFactory, LodashDecorator } from './factory';
import { PostValueApplicator } from './applicators';

const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(before, new PostValueApplicator(), { setter: true })
);

/**
* Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times.
* Subsequent calls to the created function return the result of the last func invocation.
Expand Down Expand Up @@ -29,8 +34,8 @@ import { PostValueApplicator } from './applicators';
*
* calls === 3; // => true
*/
export const BeforeAll: (n: number) => LodashDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(before, new PostValueApplicator(), { setter: true })
);
export function BeforeAll(n: number): LodashDecorator {
return decorator(n);
}
export { BeforeAll as beforeAll };
export default BeforeAll;
export default decorator;
13 changes: 9 additions & 4 deletions src/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import bind = require('lodash/bind');

import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { BindApplicator } from './applicators';

const decorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(bind, new BindApplicator())
);

/**
* Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.
*
Expand All @@ -27,8 +32,8 @@ import { BindApplicator } from './applicators';
* myClass.bound.call(null); // => myClass {}
* myClass.unbound.call(null); // => null
*/
export const Bind: (...partials: any[]) => LodashMethodDecorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(bind, new BindApplicator())
);
export function Bind(...partials: any[]): LodashMethodDecorator {
return decorator(...partials);
}
export { Bind as bind };
export default Bind;
export default decorator;
13 changes: 9 additions & 4 deletions src/curry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import curry = require('lodash/curry');

import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';

const decorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(curry, new PreValueApplicator(), { bound: true })
);

/**
* Creates a function that accepts arguments of func and either invokes func returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining func arguments, and so on.
* The arity of func may be specified if func.length is not sufficient.
Expand All @@ -28,8 +33,8 @@ import { PreValueApplicator } from './applicators';
*
* add5AndMultiply(10); // => 30
*/
export const Curry: (arity?: number) => LodashMethodDecorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(curry, new PreValueApplicator(), { bound: true })
);
export function Curry(arity?: number): LodashMethodDecorator {
return decorator(arity);
}
export { Curry as curry };
export default Curry;
export default decorator;
13 changes: 9 additions & 4 deletions src/curryAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import curry = require('lodash/curry');

import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';

const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(curry, new PreValueApplicator())
);

/**
* Creates a function that accepts arguments of func and either invokes func returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining func arguments, and so on.
* The arity of func may be specified if func.length is not sufficient.
Expand All @@ -26,8 +31,8 @@ import { PreValueApplicator } from './applicators';
*
* add5AndMultiply(10); // => 15
*/
export const CurryAll: (arity?: number) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(curry, new PreValueApplicator())
);
export function CurryAll(arity?: number): LodashMethodDecorator {
return decorator(arity);
}
export { CurryAll as curryAll };
export default CurryAll;
export default decorator;
13 changes: 9 additions & 4 deletions src/curryRight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import curryRight = require('lodash/curryRight');

import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';

const decorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(curryRight, new PreValueApplicator(), { bound: true })
);

/**
* This method is like _.curry except that arguments are applied to func in the manner of _.partialRight instead of _.partial.
* The arity of func may be specified if func.length is not sufficient.
Expand All @@ -28,8 +33,8 @@ import { PreValueApplicator } from './applicators';
*
* add5AndMultiply(10); // => 30
*/
export const CurryRight: (arity?: number) => LodashMethodDecorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(curryRight, new PreValueApplicator(), { bound: true })
);
export function CurryRight(arity?: number): LodashMethodDecorator {
return decorator(arity);
}
export { CurryRight as curryRight };
export default CurryRight;
export default decorator;
13 changes: 9 additions & 4 deletions src/curryRightAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import curryRight = require('lodash/curryRight');

import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';

const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(curryRight, new PreValueApplicator())
);

/**
* This method is like _.curry except that arguments are applied to func in the manner of _.partialRight instead of _.partial.
* The arity of func may be specified if func.length is not sufficient.
Expand All @@ -26,8 +31,8 @@ import { PreValueApplicator } from './applicators';
*
* add5AndMultiply(10); // => 15
*/
export const CurryRightAll: (arity?: number) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(curryRight, new PreValueApplicator())
);
export function CurryRightAll(arity?: number): LodashMethodDecorator {
return decorator(arity);
}
export { CurryRightAll as curryRightAll };
export default CurryRightAll;
export default decorator;
14 changes: 9 additions & 5 deletions src/debounce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import debounce = require('lodash/debounce');
import { DecoratorConfig, DecoratorFactory, LodashDecorator } from './factory';
import { PreValueApplicator } from './applicators';
import { DebounceOptions } from './shared';

const decorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(debounce, new PreValueApplicator(), { setter: true })
);

/**
* Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.
* The debounced function comes with a cancel method to cancel delayed func invocations and a flush method to immediately invoke them.
Expand Down Expand Up @@ -38,9 +43,8 @@ import { DebounceOptions } from './shared';
* myClass.value; // => 120;
* }, 11);
*/
export const Debounce: (wait?: number, options?: DebounceOptions) => LodashDecorator = DecoratorFactory.createInstanceDecorator(
new DecoratorConfig(debounce, new PreValueApplicator(), { setter: true })
);

export function Debounce(wait?: number, options?: DebounceOptions): LodashDecorator {
return decorator(wait, options);
}
export { Debounce as debounce };
export default Debounce;
export default decorator;
13 changes: 9 additions & 4 deletions src/debounceAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import debounce = require('lodash/debounce');
import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';
import { DebounceOptions } from './shared';

const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(debounce, new PreValueApplicator())
);

/**
* Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.
* The debounced function comes with a cancel method to cancel delayed func invocations and a flush method to immediately invoke them.
Expand Down Expand Up @@ -40,8 +45,8 @@ import { DebounceOptions } from './shared';
* myClass.value; // => 120;
* }, 11);
*/
export const DebounceAll: (wait?: number, options?: DebounceOptions) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(debounce, new PreValueApplicator())
);
export function DebounceAll(wait?: number, options?: DebounceOptions): LodashMethodDecorator {
return decorator(wait, options);
}
export { DebounceAll as debounceAll };
export default DebounceAll;
export default decorator;
13 changes: 9 additions & 4 deletions src/defer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import defer = require('lodash/defer');

import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { InvokeApplicator } from './applicators';

const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(defer, new InvokeApplicator(), { setter: true })
);

/**
* Defers invoking the func until the current call stack has cleared. Any additional arguments are provided to func when it's invoked.
*
Expand All @@ -27,8 +32,8 @@ import { InvokeApplicator } from './applicators';
* myClass.value; // => 110;
* }, 0);
*/
export const Defer: (...args: any[]) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(defer, new InvokeApplicator(), { setter: true })
);
export function Defer(...args: any[]): LodashMethodDecorator {
return decorator(...args);
}
export { Defer as defer };
export default Defer;
export default decorator;
29 changes: 17 additions & 12 deletions src/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ import delay = require('lodash/delay');

import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';

const decorator = DecoratorFactory.createDecorator(
new DecoratorConfig(
function(value: Function, wait: number, ...args: any[]) {
return function(...invokeArgs: any[]): any {
return delay(value.bind(this), wait, ...invokeArgs, ...args);
};
},
new PreValueApplicator(),
{ setter: true }
)
);

/**
* Invokes func after wait milliseconds. Any additional arguments are provided to func when it's invoked.
*
Expand All @@ -28,16 +41,8 @@ import { PreValueApplicator } from './applicators';
* myClass.value; // => 110;
* }, 30);
*/
export const Delay: (wait: number, ...args: any[]) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(
function(value: Function, wait: number, ...args: any[]) {
return function(...invokeArgs: any[]): any {
return delay(value.bind(this), wait, ...invokeArgs, ...args);
};
},
new PreValueApplicator(),
{ setter: true }
)
);
export function Delay(wait: number, ...args: any[]): LodashMethodDecorator {
return decorator(wait, ...args);
}
export { Delay as delay };
export default Delay;
export default decorator;
Loading

0 comments on commit d0a602d

Please sign in to comment.