@shopify/react-effect
Advanced tools
Comparing version 5.0.3 to 5.1.0
@@ -10,7 +10,5 @@ 'use strict'; | ||
const manager = React.useContext(context.EffectContext); | ||
if (manager == null || kind != null && !manager.shouldPerform(kind)) { | ||
return; | ||
} | ||
manager.add(perform(), kind); | ||
@@ -17,0 +15,0 @@ } |
@@ -9,3 +9,2 @@ 'use strict'; | ||
} | ||
constructor({ | ||
@@ -18,3 +17,2 @@ include = true | ||
} | ||
reset() { | ||
@@ -24,3 +22,2 @@ this.effects = []; | ||
} | ||
add(effect, kind) { | ||
@@ -30,18 +27,13 @@ if (kind != null) { | ||
} | ||
if (effect == null || typeof effect !== 'object' || !('then' in effect)) { | ||
return; | ||
} | ||
this.effects.push(effect); | ||
} | ||
async resolve() { | ||
await Promise.all(this.effects); | ||
} | ||
async betweenEachPass(pass) { | ||
await Promise.all([...this.kinds].map(kind => typeof kind.betweenEachPass === 'function' ? kind.betweenEachPass(pass) : Promise.resolve())); | ||
} | ||
async afterEachPass(pass) { | ||
@@ -51,3 +43,2 @@ const results = await Promise.all([...this.kinds].map(kind => typeof kind.afterEachPass === 'function' ? kind.afterEachPass(pass) : Promise.resolve())); | ||
} | ||
shouldPerform(kind) { | ||
@@ -57,12 +48,9 @@ const { | ||
} = this; | ||
if (!include) { | ||
return false; | ||
} | ||
return include === true || kind != null && include.includes(kind.id); | ||
} | ||
} | ||
exports.EffectManager = EffectManager; |
@@ -35,3 +35,2 @@ 'use strict'; | ||
const cancelled = !manager$1.finished && index + 1 >= maxPasses; | ||
if (manager$1.finished || cancelled) { | ||
@@ -46,3 +45,2 @@ const duration = Date.now() - start; | ||
}); | ||
if (afterEachPass) { | ||
@@ -57,3 +55,2 @@ await afterEachPass({ | ||
} | ||
return result; | ||
@@ -73,3 +70,2 @@ } else { | ||
})) && performNextPass; | ||
if (afterEachPass) { | ||
@@ -84,3 +80,2 @@ performNextPass = shouldContinue(await afterEachPass({ | ||
} | ||
if (performNextPass) { | ||
@@ -94,3 +89,2 @@ await manager$1.betweenEachPass({ | ||
}); | ||
if (betweenEachPass) { | ||
@@ -106,3 +100,2 @@ await betweenEachPass({ | ||
} | ||
manager$1.reset(); | ||
@@ -113,7 +106,5 @@ return performNextPass ? perform(index + 1) : result; | ||
} | ||
function shouldContinue(result) { | ||
return result !== false; | ||
} | ||
function identity(value) { | ||
@@ -120,0 +111,0 @@ return value; |
@@ -8,7 +8,5 @@ 'use strict'; | ||
const NoopComponent = () => null; | ||
NoopComponent.displayName = Component.displayName || Component.name; | ||
return NoopComponent; | ||
} | ||
return Component; | ||
@@ -15,0 +13,0 @@ } |
{ | ||
"name": "@shopify/react-effect", | ||
"version": "5.0.3", | ||
"version": "5.1.0", | ||
"license": "MIT", | ||
@@ -31,3 +31,3 @@ "description": "A component and set of utilities for performing effects within a universal React app", | ||
"engines": { | ||
"node": "^14.17.0 || >=16.0.0" | ||
"node": ">=18.12.0" | ||
}, | ||
@@ -46,7 +46,7 @@ "files": [ | ||
"peerDependencies": { | ||
"react": ">=16.8.0 <19.0.0", | ||
"react": ">=18.0.0 <19.0.0", | ||
"react-dom": ">=16.8.0 <19.0.0" | ||
}, | ||
"devDependencies": { | ||
"@shopify/jest-dom-mocks": "^4.1.1" | ||
"@shopify/jest-dom-mocks": "^5.1.0" | ||
}, | ||
@@ -53,0 +53,0 @@ "module": "index.mjs", |
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
30548