@shopify/react-effect
Advanced tools
Comparing version 3.0.4 to 3.1.0
@@ -10,2 +10,8 @@ # Changelog | ||
## [3.1.0] - 2019-06-14 | ||
### Added | ||
- You can now bail out of render passes in `extract` by returning `false` (or a promise that resolves to `false`) from `betweenEachPass`/ `afterEachPass` ([#747](https://github.com/Shopify/quilt/pull/747)) | ||
## [3.0.0] - 2019-04-08 | ||
@@ -12,0 +18,0 @@ |
@@ -13,6 +13,6 @@ import { EffectKind, Pass } from './types'; | ||
resolve(): Promise<void>; | ||
betweenEachPass(pass: Pass): void; | ||
afterEachPass(pass: Pass): void; | ||
betweenEachPass(pass: Pass): Promise<boolean>; | ||
afterEachPass(pass: Pass): Promise<boolean>; | ||
shouldPerform(kind: EffectKind): boolean; | ||
} | ||
export {}; |
@@ -40,38 +40,36 @@ "use strict"; | ||
EffectManager.prototype.betweenEachPass = function (pass) { | ||
var e_1, _a; | ||
try { | ||
for (var _b = tslib_1.__values(this.kinds), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var kind = _c.value; | ||
if (typeof kind.betweenEachPass === 'function') { | ||
kind.betweenEachPass(pass); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var results; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(tslib_1.__spread(this.kinds).map(function (kind) { | ||
return typeof kind.betweenEachPass === 'function' | ||
? kind.betweenEachPass(pass) | ||
: Promise.resolve(); | ||
}))]; | ||
case 1: | ||
results = _a.sent(); | ||
return [2 /*return*/, results.every(function (result) { return result !== false; })]; | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
}); | ||
}); | ||
}; | ||
EffectManager.prototype.afterEachPass = function (pass) { | ||
var e_2, _a; | ||
try { | ||
for (var _b = tslib_1.__values(this.kinds), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var kind = _c.value; | ||
if (typeof kind.afterEachPass === 'function') { | ||
kind.afterEachPass(pass); | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var results; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(tslib_1.__spread(this.kinds).map(function (kind) { | ||
return typeof kind.afterEachPass === 'function' | ||
? kind.afterEachPass(pass) | ||
: Promise.resolve(); | ||
}))]; | ||
case 1: | ||
results = _a.sent(); | ||
this.effects = []; | ||
this.kinds = new Set(); | ||
return [2 /*return*/, results.every(function (result) { return result !== false; })]; | ||
} | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
this.effects = []; | ||
this.kinds = new Set(); | ||
}); | ||
}); | ||
}; | ||
@@ -78,0 +76,0 @@ EffectManager.prototype.shouldPerform = function (kind) { |
@@ -18,5 +18,5 @@ "use strict"; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var start, result, duration, resolveStart, renderDuration, resolveDuration; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
var start, result, duration, resolveStart, renderDuration, resolveDuration, performNextPass, _a, _b, _c, _d; | ||
return tslib_1.__generator(this, function (_e) { | ||
switch (_e.label) { | ||
case 0: | ||
@@ -34,3 +34,3 @@ start = Date.now(); | ||
case 1: | ||
_a.sent(); | ||
_e.sent(); | ||
if (!afterEachPass) return [3 /*break*/, 3]; | ||
@@ -44,4 +44,4 @@ return [4 /*yield*/, afterEachPass({ | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
_e.sent(); | ||
_e.label = 3; | ||
case 3: return [2 /*return*/, result]; | ||
@@ -53,4 +53,6 @@ case 4: | ||
case 5: | ||
_a.sent(); | ||
_e.sent(); | ||
resolveDuration = Date.now() - resolveStart; | ||
performNextPass = true; | ||
_a = shouldContinue; | ||
return [4 /*yield*/, manager.betweenEachPass({ | ||
@@ -63,4 +65,6 @@ index: index, | ||
case 6: | ||
_a.sent(); | ||
performNextPass = | ||
_a.apply(void 0, [_e.sent()]) && performNextPass; | ||
if (!betweenEachPass) return [3 /*break*/, 8]; | ||
_b = shouldContinue; | ||
return [4 /*yield*/, betweenEachPass({ | ||
@@ -73,13 +77,18 @@ index: index, | ||
case 7: | ||
_a.sent(); | ||
_a.label = 8; | ||
case 8: return [4 /*yield*/, manager.afterEachPass({ | ||
index: index, | ||
finished: false, | ||
renderDuration: renderDuration, | ||
resolveDuration: resolveDuration, | ||
})]; | ||
performNextPass = | ||
_b.apply(void 0, [_e.sent()]) && performNextPass; | ||
_e.label = 8; | ||
case 8: | ||
_c = shouldContinue; | ||
return [4 /*yield*/, manager.afterEachPass({ | ||
index: index, | ||
finished: false, | ||
renderDuration: renderDuration, | ||
resolveDuration: resolveDuration, | ||
})]; | ||
case 9: | ||
_a.sent(); | ||
performNextPass = | ||
_c.apply(void 0, [_e.sent()]) && performNextPass; | ||
if (!afterEachPass) return [3 /*break*/, 11]; | ||
_d = shouldContinue; | ||
return [4 /*yield*/, afterEachPass({ | ||
@@ -92,6 +101,7 @@ index: index, | ||
case 10: | ||
_a.sent(); | ||
_a.label = 11; | ||
performNextPass = | ||
_d.apply(void 0, [_e.sent()]) && performNextPass; | ||
_e.label = 11; | ||
case 11: | ||
if (index + 1 >= maxPasses) { | ||
if (index + 1 >= maxPasses || !performNextPass) { | ||
return [2 /*return*/, result]; | ||
@@ -106,4 +116,7 @@ } | ||
exports.extract = extract; | ||
function shouldContinue(result) { | ||
return result !== false; | ||
} | ||
function identity(value) { | ||
return value; | ||
} |
{ | ||
"name": "@shopify/react-effect", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A component and set of utilities for performing effects within a universal React app", |
@@ -78,5 +78,5 @@ # `@shopify/react-effect` | ||
- `betweenEachPass`: a function that is called after a pass of your tree that did not "finish" (that is, there were still promises that got collected). This function can return a promise, and it will be waited on before continuing. It is called with a single argument: a `Pass` object, which contains the `index`, `finished`, `renderDuration` and `resolveDuration` of the just-completed pass. | ||
- `betweenEachPass`: a function that is called after a pass of your tree that did not "finish" (that is, there were still promises that got collected). This function can return a promise, and it will be waited on before continuing. It is called with a single argument: a `Pass` object, which contains the `index`, `finished`, `renderDuration` and `resolveDuration` of the just-completed pass. Returning `false` (or a promise that resolves to `false`) from this method will bail out of subsequent passes. | ||
- `afterEachPass`: a function that is called after each pass of your tree, regardless of whether traversal is "finished". This function can return a promise, and it will be waited on before continuing. This function is called with the same argument as the `betweenEachPass` option. | ||
- `afterEachPass`: a function that is called after each pass of your tree, regardless of whether traversal is "finished". This function can return a promise, and it will be waited on before continuing. This function is called with the same argument as the `betweenEachPass` option. Returning `false` (or a promise for `false`) from this method will bail out of subsequent passes. | ||
@@ -83,0 +83,0 @@ - `decorate`: a function that takes the root React element in your tree and returns a new tree to use. You can use this to wrap your application in context providers that only your server render requires. |
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
22537
309