nemo-observable-util
Advanced tools
Comparing version 5.0.8 to 5.1.0
@@ -196,3 +196,2 @@ 'use strict'; | ||
} | ||
function flush() { | ||
@@ -345,2 +344,3 @@ runnerManager.flush(); | ||
var action = decoratorFactory(createAction); | ||
var asyncAction = decoratorFactory(createAsyncAction); | ||
var actionManager = new StackManager(); | ||
@@ -377,3 +377,39 @@ | ||
} | ||
function createAsyncAction(originalFunc) { | ||
if (typeof originalFunc !== 'function') { | ||
throw new Error('action should must wrap on Function: ' + typeof originalFunc); | ||
} | ||
var actionId = actionManager.getUUID(); | ||
var transactionId = transactionManager.getUUID(); | ||
return function () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var start = function () { | ||
actionManager.start(actionId); | ||
transactionManager.start(transactionId); | ||
}; | ||
var end = function () { | ||
transactionManager.end(transactionId); | ||
actionManager.end(actionId); | ||
}; | ||
var res; | ||
try { | ||
start(); | ||
res = originalFunc.apply(this, args); | ||
if (!res || !res.then || typeof res.then !== 'function') { | ||
throw new Error('asyncAction should must wrap on Async Function: ' + originalFunc.name); | ||
} | ||
if (!res.finally) { | ||
res.then(end); | ||
res.catch(end); | ||
} else { | ||
res.finally(end); | ||
} | ||
} finally { | ||
end(); | ||
} | ||
return res; | ||
}; | ||
} | ||
function runInAction(fn) { | ||
@@ -701,2 +737,3 @@ return action(fn)(); | ||
exports.runInAction = runInAction; | ||
exports.asyncAction = asyncAction; | ||
exports.decoratorFactory = decoratorFactory; |
@@ -184,3 +184,2 @@ 'use strict'; | ||
} | ||
function flush() { | ||
@@ -324,2 +323,3 @@ runnerManager.flush(); | ||
const action = decoratorFactory(createAction); | ||
const asyncAction = decoratorFactory(createAsyncAction); | ||
const actionManager = new StackManager(); | ||
@@ -353,3 +353,36 @@ | ||
} | ||
function createAsyncAction(originalFunc) { | ||
if (typeof originalFunc !== 'function') { | ||
throw new Error('action should must wrap on Function: ' + typeof originalFunc); | ||
} | ||
const actionId = actionManager.getUUID(); | ||
const transactionId = transactionManager.getUUID(); | ||
return function (...args) { | ||
const start = () => { | ||
actionManager.start(actionId); | ||
transactionManager.start(transactionId); | ||
}; | ||
const end = () => { | ||
transactionManager.end(transactionId); | ||
actionManager.end(actionId); | ||
}; | ||
let res; | ||
try { | ||
start(); | ||
res = originalFunc.apply(this, args); | ||
if (!res || !res.then || typeof res.then !== 'function') { | ||
throw new Error('asyncAction should must wrap on Async Function: ' + originalFunc.name); | ||
} | ||
if (!res.finally) { | ||
res.then(end); | ||
res.catch(end); | ||
} else { | ||
res.finally(end); | ||
} | ||
} finally { | ||
end(); | ||
} | ||
return res; | ||
}; | ||
} | ||
function runInAction(fn) { | ||
@@ -662,2 +695,3 @@ return action(fn)(); | ||
exports.runInAction = runInAction; | ||
exports.asyncAction = asyncAction; | ||
exports.decoratorFactory = decoratorFactory; |
@@ -192,3 +192,2 @@ var connectionStore = new WeakMap(); | ||
} | ||
function flush() { | ||
@@ -341,2 +340,3 @@ runnerManager.flush(); | ||
var action = decoratorFactory(createAction); | ||
var asyncAction = decoratorFactory(createAsyncAction); | ||
var actionManager = new StackManager(); | ||
@@ -373,3 +373,39 @@ | ||
} | ||
function createAsyncAction(originalFunc) { | ||
if (typeof originalFunc !== 'function') { | ||
throw new Error('action should must wrap on Function: ' + typeof originalFunc); | ||
} | ||
var actionId = actionManager.getUUID(); | ||
var transactionId = transactionManager.getUUID(); | ||
return function () { | ||
var args = [], len = arguments.length; | ||
while ( len-- ) args[ len ] = arguments[ len ]; | ||
var start = function () { | ||
actionManager.start(actionId); | ||
transactionManager.start(transactionId); | ||
}; | ||
var end = function () { | ||
transactionManager.end(transactionId); | ||
actionManager.end(actionId); | ||
}; | ||
var res; | ||
try { | ||
start(); | ||
res = originalFunc.apply(this, args); | ||
if (!res || !res.then || typeof res.then !== 'function') { | ||
throw new Error('asyncAction should must wrap on Async Function: ' + originalFunc.name); | ||
} | ||
if (!res.finally) { | ||
res.then(end); | ||
res.catch(end); | ||
} else { | ||
res.finally(end); | ||
} | ||
} finally { | ||
end(); | ||
} | ||
return res; | ||
}; | ||
} | ||
function runInAction(fn) { | ||
@@ -683,2 +719,2 @@ return action(fn)(); | ||
export { observe, unobserve, observable, isObservable, raw, config, startTransaction, endTransaction, withTransaction, transactionManager, flush, action, actionManager, runInAction, decoratorFactory }; | ||
export { observe, unobserve, observable, isObservable, raw, config, startTransaction, endTransaction, withTransaction, transactionManager, flush, action, actionManager, runInAction, asyncAction, decoratorFactory }; |
@@ -180,3 +180,2 @@ const connectionStore = new WeakMap(); | ||
} | ||
function flush() { | ||
@@ -320,2 +319,3 @@ runnerManager.flush(); | ||
const action = decoratorFactory(createAction); | ||
const asyncAction = decoratorFactory(createAsyncAction); | ||
const actionManager = new StackManager(); | ||
@@ -349,3 +349,36 @@ | ||
} | ||
function createAsyncAction(originalFunc) { | ||
if (typeof originalFunc !== 'function') { | ||
throw new Error('action should must wrap on Function: ' + typeof originalFunc); | ||
} | ||
const actionId = actionManager.getUUID(); | ||
const transactionId = transactionManager.getUUID(); | ||
return function (...args) { | ||
const start = () => { | ||
actionManager.start(actionId); | ||
transactionManager.start(transactionId); | ||
}; | ||
const end = () => { | ||
transactionManager.end(transactionId); | ||
actionManager.end(actionId); | ||
}; | ||
let res; | ||
try { | ||
start(); | ||
res = originalFunc.apply(this, args); | ||
if (!res || !res.then || typeof res.then !== 'function') { | ||
throw new Error('asyncAction should must wrap on Async Function: ' + originalFunc.name); | ||
} | ||
if (!res.finally) { | ||
res.then(end); | ||
res.catch(end); | ||
} else { | ||
res.finally(end); | ||
} | ||
} finally { | ||
end(); | ||
} | ||
return res; | ||
}; | ||
} | ||
function runInAction(fn) { | ||
@@ -644,2 +677,2 @@ return action(fn)(); | ||
export { observe, unobserve, observable, isObservable, raw, config, startTransaction, endTransaction, withTransaction, transactionManager, flush, action, actionManager, runInAction, decoratorFactory }; | ||
export { observe, unobserve, observable, isObservable, raw, config, startTransaction, endTransaction, withTransaction, transactionManager, flush, action, actionManager, runInAction, asyncAction, decoratorFactory }; |
{ | ||
"name": "nemo-observable-util", | ||
"version": "5.0.8", | ||
"version": "5.1.0", | ||
"description": "Simple transparent reactivity with 100% language coverage. Made with ES6 Proxies.", | ||
@@ -56,2 +56,3 @@ "main": "dist/cjs.es5.js", | ||
"chai": "^4.1.2", | ||
"chai-as-promised": "^7.1.1", | ||
"coveralls": "^3.0.1", | ||
@@ -58,0 +59,0 @@ "del": "^5.1.0", |
@@ -51,2 +51,9 @@ declare module 'nemo-observable-util' { | ||
function action(target: Object, propertyKey: string | symbol): void; | ||
function asyncAction<F extends Function>(fn: F): F; | ||
function asyncAction<T>( | ||
target: Object, | ||
propertyKey: string | symbol, | ||
descriptor: TypedPropertyDescriptor<T> | ||
): TypedPropertyDescriptor<T> | void; | ||
function asyncAction(target: Object, propertyKey: string | symbol): void; | ||
function runInAction<T extends (...args: any) => any>(f: T): ReturnType<T>; | ||
@@ -53,0 +60,0 @@ const actionManager: any; |
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
112516
2577
32