@fangxq/async-context
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -8,5 +8,4 @@ export const asyncContext: { | ||
clearAll(): void | ||
useAsync<T>(token: string, fn: () => Promise<T>): Promise<T> | ||
useSync<T>(token: string, fn: () => T): T | ||
use<T>(token: string, fn: () => Promise<T>): Promise<T> | ||
getCurrentContext(): string | ||
} |
20
index.js
@@ -37,3 +37,3 @@ const cloneDeep = require('lodash').cloneDeep | ||
function getPrivateValues() { | ||
const token = store.getStore() ?? syncToken | ||
const token = store.getStore() | ||
if (!self.privateValues[token]) { | ||
@@ -59,7 +59,5 @@ self.privateValues[token] = cloneDeep(self.defaultPrivateValues) | ||
let syncToken = '' | ||
module.exports.asyncContext = { | ||
definePrivate(path, proName, defaultValue) { | ||
if (!dataContext[path]) dataContext[path] = new contextObject() | ||
if(!dataContext[path]) dataContext[path] = new contextObject() | ||
@@ -69,3 +67,3 @@ dataContext[path].definePrivateValue(proName, defaultValue) | ||
definePublic(path, proName, defaultValue) { | ||
if (!dataContext[path]) dataContext[path] = new contextObject() | ||
if(!dataContext[path]) dataContext[path] = new contextObject() | ||
@@ -90,3 +88,3 @@ dataContext[path].definePublicValue(proName, defaultValue) | ||
}, | ||
useAsync(token, fn) { | ||
use(token, fn) { | ||
return new Promise((resolve, reject) => { | ||
@@ -102,13 +100,5 @@ store.run(token, async () => { | ||
}, | ||
useSync(token, fn) { | ||
try { | ||
syncToken = token | ||
return fn() | ||
} finally { | ||
syncToken = '' | ||
} | ||
}, | ||
getCurrentContext() { | ||
return store.getStore() ?? syncToken | ||
return store.getStore() | ||
} | ||
} |
{ | ||
"name": "@fangxq/async-context", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
3581
96