typescript-state-machine
Advanced tools
Comparing version 0.9.3 to 0.9.4
@@ -56,4 +56,5 @@ export declare namespace fsm { | ||
function CheckStateIn(states: State[], message?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
function CheckStateNotIn(states: State[], message?: string): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
function AssumeStateIs(state: State): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
function AssumeStateIsNot(state: State): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; | ||
} |
@@ -82,3 +82,3 @@ "use strict"; | ||
catch (e) { | ||
this.log.warn('Uncaught error in listener :' + e); | ||
this.log.error('Uncaught error in listener', e); | ||
} | ||
@@ -254,2 +254,37 @@ } | ||
/* | ||
Method annotator. Throw an error if the state when the method is called | ||
is one of the given states | ||
*/ | ||
function CheckStateNotIn(states, message) { | ||
return function (target, propertyKey, descriptor) { | ||
var originalMethod; | ||
if (descriptor.value) { | ||
originalMethod = descriptor.value; | ||
descriptor.value = function () { | ||
var context = this; | ||
if (states.indexOf(context.state) === -1) { | ||
return originalMethod.apply(context, arguments); | ||
} | ||
else { | ||
throw new Error(message || 'Illegal execution of ' + propertyKey + ' : State should not be one of ' + states); | ||
} | ||
}; | ||
} | ||
else if (descriptor.get) { | ||
var originalGetter_2 = descriptor.get; | ||
descriptor.get = function () { | ||
var context = this; | ||
if (states.indexOf(context.state) === -1) { | ||
return originalGetter_2.apply(context, arguments); | ||
} | ||
else { | ||
throw new Error(message || 'Illegal execution of ' + propertyKey + ' : State should not be one of these states: ' + states); | ||
} | ||
}; | ||
} | ||
return descriptor; | ||
}; | ||
} | ||
fsm.CheckStateNotIn = CheckStateNotIn; | ||
/* | ||
Method annotator. Skip the method execution if the state when the method is called | ||
@@ -256,0 +291,0 @@ is different from the given state |
{ | ||
"name": "typescript-state-machine", | ||
"version": "0.9.3", | ||
"version": "0.9.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -128,3 +128,3 @@ import { getLogger } from 'log4javascript' | ||
} catch (e) { | ||
this.log.warn('Uncaught error in listener :' + e) | ||
this.log.error('Uncaught error in listener', e) | ||
} | ||
@@ -302,4 +302,34 @@ } else { | ||
} | ||
/* | ||
Method annotator. Throw an error if the state when the method is called | ||
is one of the given states | ||
*/ | ||
export function CheckStateNotIn(states: State[], message?: string) { | ||
return function(target: any, propertyKey: string, descriptor: PropertyDescriptor) { | ||
let originalMethod: any | ||
if (descriptor.value) { | ||
originalMethod = descriptor.value | ||
descriptor.value = function() { | ||
const context = this as StateMachine<any> | ||
if (states.indexOf(context.state) === -1) { | ||
return originalMethod.apply(context, arguments) | ||
} else { | ||
throw new Error(message || 'Illegal execution of ' + propertyKey + ' : State should not be one of ' + states) | ||
} | ||
} | ||
} else if (descriptor.get) { | ||
const originalGetter = descriptor.get | ||
descriptor.get = function() { | ||
const context = this as StateMachine<any> | ||
if (states.indexOf(context.state) === -1) { | ||
return originalGetter.apply(context, arguments) | ||
} else { | ||
throw new Error(message || 'Illegal execution of ' + propertyKey + ' : State should not be one of these states: ' + states) | ||
} | ||
} | ||
} | ||
return descriptor | ||
} | ||
} | ||
/* | ||
Method annotator. Skip the method execution if the state when the method is called | ||
@@ -306,0 +336,0 @@ is different from the given state |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
161470
761
0