-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(decorators): negate, flip, rearg can now be used on properties
- Loading branch information
1 parent
59b5485
commit 6f951dc
Showing
12 changed files
with
153 additions
and
21 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
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,20 @@ | ||
import isFunction = require('lodash/isFunction'); | ||
|
||
import { Applicator, ApplicateOptions } from './Applicator'; | ||
import { resolveFunction } from '../utils'; | ||
|
||
export class PartialValueApplicator extends Applicator { | ||
apply({ args, target, value, config: { execute } }: ApplicateOptions): any { | ||
return function(...invokeArgs: any[]): any { | ||
let fn = value; | ||
let argIndex = 0; | ||
|
||
if (!isFunction(fn)) { | ||
fn = resolveFunction(args[0], this, target); | ||
argIndex = 1; | ||
} | ||
|
||
return execute(fn, ...args.slice(argIndex)).apply(this, invokeArgs); | ||
} | ||
} | ||
} |
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
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
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
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,10 +1,15 @@ | ||
import negate = require('lodash/negate'); | ||
|
||
import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory'; | ||
import { PreValueApplicator } from './applicators'; | ||
import { | ||
DecoratorConfig, | ||
DecoratorFactory, | ||
LodashDecorator, | ||
ResolvableFunction | ||
} from './factory'; | ||
import { PartialValueApplicator } from './applicators'; | ||
|
||
export const Negate: () => LodashMethodDecorator = DecoratorFactory.createDecorator( | ||
new DecoratorConfig(negate, new PreValueApplicator()) | ||
export const Negate: (fn?: ResolvableFunction) => LodashDecorator = DecoratorFactory.createInstanceDecorator( | ||
new DecoratorConfig(negate, new PartialValueApplicator(), { property: true }) | ||
); | ||
export { Negate as negate }; | ||
export default Negate; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import rearg = require('lodash/rearg'); | ||
|
||
import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory'; | ||
import { PreValueApplicator } from './applicators'; | ||
import { | ||
DecoratorConfig, | ||
DecoratorFactory, | ||
LodashDecorator, | ||
ResolvableFunction | ||
} from './factory'; | ||
import { PartialValueApplicator } from './applicators'; | ||
|
||
export const Rearg: (indexes: number|number[], ...args: number[]) => LodashMethodDecorator = DecoratorFactory.createDecorator( | ||
new DecoratorConfig(rearg, new PreValueApplicator()) | ||
export const Rearg: (indexes: ResolvableFunction|number|number[], ...args: (number|number[])[]) => LodashDecorator = DecoratorFactory.createInstanceDecorator( | ||
new DecoratorConfig(rearg, new PartialValueApplicator(), { property: true }) | ||
); | ||
export { Rearg as rearg }; | ||
export default Rearg; |