Comparing version 2.0.0-alpha.12 to 2.0.0-alpha.13
import { Handle } from './interfaces'; | ||
/** | ||
* An object that provides the necessary APIs to be MapLike | ||
*/ | ||
export interface MapLike<K, V> { | ||
get(key: K): V; | ||
set(key: K, value?: V): this; | ||
} | ||
export interface Indexable { | ||
[method: string]: any; | ||
} | ||
/** | ||
* The types of objects or maps where advice can be applied | ||
*/ | ||
export declare type Targetable = MapLike<string, any> | Indexable; | ||
/** | ||
* Attaches "after" advice to be executed after the original method. | ||
* The advising function will receive the original method's return value and arguments object. | ||
* The value it returns will be returned from the method when it is called (even if the return value is undefined). | ||
* | ||
* @param target Object whose method will be aspected | ||
@@ -11,5 +26,6 @@ * @param methodName Name of method to aspect | ||
*/ | ||
export declare function after(target: any, methodName: string, advice: (originalReturn: any, originalArgs: IArguments) => any): Handle; | ||
export declare function after(target: Targetable, methodName: string, advice: (originalReturn: any, originalArgs: IArguments) => any): Handle; | ||
/** | ||
* Attaches "around" advice around the original method. | ||
* | ||
* @param target Object whose method will be aspected | ||
@@ -20,5 +36,6 @@ * @param methodName Name of method to aspect | ||
*/ | ||
export declare function around(target: any, methodName: string, advice: null | ((previous: Function) => Function)): Handle; | ||
export declare function around(target: Targetable, methodName: string, advice: ((previous: Function) => Function)): Handle; | ||
/** | ||
* Attaches "before" advice to be executed before the original method. | ||
* | ||
* @param target Object whose method will be aspected | ||
@@ -29,3 +46,3 @@ * @param methodName Name of method to aspect | ||
*/ | ||
export declare function before(target: any, methodName: string, advice: (...originalArgs: any[]) => any[] | void): Handle; | ||
export declare function before(target: Targetable, methodName: string, advice: (...originalArgs: any[]) => any[] | void): Handle; | ||
/** | ||
@@ -35,2 +52,3 @@ * Attaches advice to be executed after the original method. | ||
* The value it returns will be returned from the method when it is called *unless* its return value is undefined. | ||
* | ||
* @param target Object whose method will be aspected | ||
@@ -41,2 +59,2 @@ * @param methodName Name of method to aspect | ||
*/ | ||
export declare function on(target: any, methodName: string, advice: (...originalArgs: any[]) => any): Handle; | ||
export declare function on(target: Targetable, methodName: string, advice: (...originalArgs: any[]) => any): Handle; |
@@ -11,5 +11,25 @@ (function (factory) { | ||
var lang_1 = require('./lang'); | ||
/** | ||
* An internal type guard that determines if an value is MapLike or not | ||
* | ||
* @param value The value to guard against | ||
*/ | ||
function isMapLike(value) { | ||
return value && typeof value.get === 'function' && typeof value.set === 'function'; | ||
} | ||
/** | ||
* A UID for tracking advice ordering | ||
*/ | ||
var nextId = 0; | ||
/** | ||
* Internal function that advises a join point | ||
* | ||
* @param dispatcher The current advice dispatcher | ||
* @param type The type of before or after advice to apply | ||
* @param advice The advice to apply | ||
* @param receiveArguments If true, the advice will receive the arguments passed to the join point | ||
* @return The handle that will remove the advice | ||
*/ | ||
function advise(dispatcher, type, advice, receiveArguments) { | ||
var previous = dispatcher[type]; | ||
var previous = dispatcher && dispatcher[type]; | ||
var advised = { | ||
@@ -38,10 +58,9 @@ id: nextId++, | ||
else { | ||
dispatcher[type] = advised; | ||
dispatcher && (dispatcher[type] = advised); | ||
} | ||
advice = previous = null; | ||
advice = previous = undefined; | ||
return lang_1.createHandle(function () { | ||
var previous = advised ? advised.previous : null; | ||
var next = advised ? advised.next : null; | ||
if (!previous && !next) { | ||
dispatcher[type] = null; | ||
var _a = (advised || {}), _b = _a.previous, previous = _b === void 0 ? undefined : _b, _c = _a.next, next = _c === void 0 ? undefined : _c; | ||
if (dispatcher && !previous && !next) { | ||
dispatcher[type] = undefined; | ||
} | ||
@@ -53,3 +72,3 @@ else { | ||
else { | ||
dispatcher[type] = next; | ||
dispatcher && (dispatcher[type] = next); | ||
} | ||
@@ -61,13 +80,20 @@ if (next) { | ||
if (advised) { | ||
advised.advice = null; | ||
delete advised.advice; | ||
} | ||
dispatcher = advised = null; | ||
dispatcher = advised = undefined; | ||
}); | ||
} | ||
/** | ||
* An internal function that resolves or creates the dispatcher for a given join point | ||
* | ||
* @param target The target object or map | ||
* @param methodName The name of the method that the dispatcher should be resolved for | ||
* @return The dispatcher | ||
*/ | ||
function getDispatcher(target, methodName) { | ||
var existing = target[methodName]; | ||
var existing = isMapLike(target) ? target.get(methodName) : target && target[methodName]; | ||
var dispatcher; | ||
if (!existing || existing.target !== target) { | ||
// no dispatcher | ||
target[methodName] = dispatcher = function () { | ||
/* There is no existing dispatcher, therefore we will create one */ | ||
dispatcher = function () { | ||
var executionId = nextId; | ||
@@ -101,2 +127,8 @@ var args = arguments; | ||
}; | ||
if (isMapLike(target)) { | ||
target.set(methodName, dispatcher); | ||
} | ||
else { | ||
target && (target[methodName] = dispatcher); | ||
} | ||
if (existing) { | ||
@@ -114,3 +146,2 @@ dispatcher.around = { | ||
} | ||
target = null; | ||
return dispatcher; | ||
@@ -122,2 +153,3 @@ } | ||
* The value it returns will be returned from the method when it is called (even if the return value is undefined). | ||
* | ||
* @param target Object whose method will be aspected | ||
@@ -134,2 +166,3 @@ * @param methodName Name of method to aspect | ||
* Attaches "around" advice around the original method. | ||
* | ||
* @param target Object whose method will be aspected | ||
@@ -153,8 +186,7 @@ * @param methodName Name of method to aspect | ||
advice: function (target, args) { | ||
return advised ? advised.apply(target, args) : previous && previous.advice ? previous.advice(target, args) : null; | ||
return advised ? advised.apply(target, args) : previous && previous.advice && previous.advice(target, args); | ||
} | ||
}; | ||
advice = null; | ||
return lang_1.createHandle(function () { | ||
advised = dispatcher = null; | ||
advised = dispatcher = undefined; | ||
}); | ||
@@ -165,2 +197,3 @@ } | ||
* Attaches "before" advice to be executed before the original method. | ||
* | ||
* @param target Object whose method will be aspected | ||
@@ -179,2 +212,3 @@ * @param methodName Name of method to aspect | ||
* The value it returns will be returned from the method when it is called *unless* its return value is undefined. | ||
* | ||
* @param target Object whose method will be aspected | ||
@@ -181,0 +215,0 @@ * @param methodName Name of method to aspect |
{ | ||
"name": "dojo-core", | ||
"version": "2.0.0-alpha.12", | ||
"version": "2.0.0-alpha.13", | ||
"description": "Basic utilites for common TypeScript development", | ||
@@ -5,0 +5,0 @@ "homepage": "http://dojotoolkit.org", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
586138
6517
2