This repository has been archived by the owner on Jul 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Showing
16 changed files
with
614 additions
and
596 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { handleDecorator } from './handleDecorator'; | ||
|
||
/** | ||
* Decorator that can be used to register a function to run as an aspect to `render` | ||
*/ | ||
export function afterRender(method: Function): (target: any) => void; | ||
export function afterRender(): (target: any, propertyKey: string) => void; | ||
export function afterRender(method?: Function) { | ||
return handleDecorator((target, propertyKey) => { | ||
target.addDecorator('afterRender', propertyKey ? target[propertyKey] : method); | ||
}); | ||
} | ||
|
||
export default afterRender; |
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,14 @@ | ||
import { handleDecorator } from './handleDecorator'; | ||
|
||
/** | ||
* Decorator that can be used to register a reducer function to run as an aspect before to `render` | ||
*/ | ||
export function beforeRender(method: Function): (target: any) => void; | ||
export function beforeRender(): (target: any, propertyKey: string) => void; | ||
export function beforeRender(method?: Function) { | ||
return handleDecorator((target, propertyKey) => { | ||
target.addDecorator('beforeRender', propertyKey ? target[propertyKey] : method); | ||
}); | ||
} | ||
|
||
export default beforeRender; |
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,24 @@ | ||
import { handleDecorator } from './handleDecorator'; | ||
import { DiffPropertyFunction } from './../interfaces'; | ||
|
||
/** | ||
* Decorator that can be used to register a function as a specific property diff | ||
* | ||
* @param propertyName The name of the property of which the diff function is applied | ||
* @param diffType The diff type, default is DiffType.AUTO. | ||
* @param diffFunction A diff function to run if diffType if DiffType.CUSTOM | ||
*/ | ||
export function diffProperty(propertyName: string, diffFunction: DiffPropertyFunction, reactionFunction?: Function) { | ||
return handleDecorator((target, propertyKey) => { | ||
target.addDecorator(`diffProperty:${propertyName}`, diffFunction.bind(null)); | ||
target.addDecorator('registeredDiffProperty', propertyName); | ||
if (reactionFunction || propertyKey) { | ||
target.addDecorator('diffReaction', { | ||
propertyName, | ||
reaction: propertyKey ? target[propertyKey] : reactionFunction | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
export default diffProperty; |
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,18 @@ | ||
/** | ||
* Generic decorator handler to take care of whether or not the decorator was called at the class level | ||
* or the method level. | ||
* | ||
* @param handler | ||
*/ | ||
export function handleDecorator(handler: (target: any, propertyKey?: string) => void) { | ||
return function (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) { | ||
if (typeof target === 'function') { | ||
handler(target.prototype, undefined); | ||
} | ||
else { | ||
handler(target, propertyKey); | ||
} | ||
}; | ||
} | ||
|
||
export default handleDecorator; |
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
Oops, something went wrong.