@applitools/dom-shared
Advanced tools
Comparing version 1.0.2 to 1.0.3
# Changelog | ||
## Unreleased | ||
## 1.0.3 - 2020/9/22 | ||
- removed rest arguments syntax | ||
## 1.0.2 - 2020/9/22 | ||
- chunkify, pollify, poll | ||
# Changelog | ||
## Unreleased |
{ | ||
"name": "@applitools/dom-shared", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "SEE LICENSE IN LICENSE", |
const poll = require('./poll'); | ||
function pollify(script, context = {}, key = 'state') { | ||
return options => (...args) => { | ||
if (!context[key]) { | ||
context[key] = {}; | ||
script(args) | ||
.then(value => (context[key].value = value)) | ||
.catch(err => (context[key].error = err.message)); | ||
} | ||
return poll(context, key, options); | ||
}; | ||
return options => | ||
function() { | ||
if (!context[key]) { | ||
context[key] = {}; | ||
script | ||
.apply(null, arguments) | ||
.then(value => (context[key].value = value)) | ||
.catch(err => (context[key].error = err.message)); | ||
} | ||
return poll(context, key, options); | ||
}; | ||
} | ||
module.exports = pollify; |
@@ -8,9 +8,9 @@ const assert = require('assert'); | ||
it('works', async () => { | ||
const func = () => new Promise(resolve => setTimeout(resolve, 100, 'result')); | ||
const func = result => new Promise(resolve => setTimeout(resolve, 100, result)); | ||
const funcPoll = pollify(func, {context: {}, key: 'key'})(); | ||
assert.strictEqual(typeof func, 'function'); | ||
const r = funcPoll(); | ||
const r = funcPoll('result'); | ||
assert.deepStrictEqual(r, {status: 'WIP'}); | ||
await delay(100); | ||
const r2 = funcPoll(); | ||
const r2 = funcPoll('result 2'); | ||
assert.deepStrictEqual(r2, {status: 'SUCCESS', value: 'result'}); | ||
@@ -17,0 +17,0 @@ }); |
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
24320
238
0