@shopify/react-effect
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -10,2 +10,8 @@ # Changelog | ||
## [3.2.0] - 2019-06-27 | ||
### Fixed | ||
- Fixed an issue where `betweenEachPass` was called on the last pass before `maxPasses` was reached. In order to correct this issue, returning `false` from `betweenEachPass` no longer halts render looping (use `afterEachPass` instead). [#769](https://github.com/Shopify/quilt/pull/769) | ||
## [3.1.0] - 2019-06-14 | ||
@@ -12,0 +18,0 @@ |
@@ -11,5 +11,6 @@ import { EffectKind, Pass } from './types'; | ||
constructor({ include }?: Options); | ||
reset(): void; | ||
add(effect: any, kind?: EffectKind): void; | ||
resolve(): Promise<void>; | ||
betweenEachPass(pass: Pass): Promise<boolean>; | ||
betweenEachPass(pass: Pass): Promise<void>; | ||
afterEachPass(pass: Pass): Promise<boolean>; | ||
@@ -16,0 +17,0 @@ shouldPerform(kind: EffectKind): boolean; |
@@ -18,2 +18,6 @@ "use strict"; | ||
}); | ||
EffectManager.prototype.reset = function () { | ||
this.effects = []; | ||
this.kinds = new Set(); | ||
}; | ||
EffectManager.prototype.add = function (effect, kind) { | ||
@@ -42,3 +46,2 @@ if (kind != null) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var results; | ||
return tslib_1.__generator(this, function (_a) { | ||
@@ -52,4 +55,4 @@ switch (_a.label) { | ||
case 1: | ||
results = _a.sent(); | ||
return [2 /*return*/, results.every(function (result) { return result !== false; })]; | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
@@ -71,4 +74,2 @@ }); | ||
results = _a.sent(); | ||
this.effects = []; | ||
this.kinds = new Set(); | ||
return [2 /*return*/, results.every(function (result) { return result !== false; })]; | ||
@@ -75,0 +76,0 @@ } |
@@ -18,13 +18,15 @@ "use strict"; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var start, result, duration, resolveStart, renderDuration, resolveDuration, performNextPass, _a, _b, _c, _d; | ||
return tslib_1.__generator(this, function (_e) { | ||
switch (_e.label) { | ||
var start, result, cancelled, duration, resolveStart, renderDuration, resolveDuration, performNextPass, _a, _b; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
start = Date.now(); | ||
result = renderFunction(element); | ||
if (!manager.finished) return [3 /*break*/, 4]; | ||
cancelled = !manager.finished && index + 1 >= maxPasses; | ||
if (!(manager.finished || cancelled)) return [3 /*break*/, 4]; | ||
duration = Date.now() - start; | ||
return [4 /*yield*/, manager.afterEachPass({ | ||
index: index, | ||
finished: manager.finished, | ||
finished: true, | ||
cancelled: cancelled, | ||
renderDuration: duration, | ||
@@ -34,7 +36,8 @@ resolveDuration: 0, | ||
case 1: | ||
_e.sent(); | ||
_c.sent(); | ||
if (!afterEachPass) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, afterEachPass({ | ||
index: index, | ||
finished: manager.finished, | ||
finished: true, | ||
cancelled: cancelled, | ||
renderDuration: duration, | ||
@@ -44,4 +47,4 @@ resolveDuration: 0, | ||
case 2: | ||
_e.sent(); | ||
_e.label = 3; | ||
_c.sent(); | ||
_c.label = 3; | ||
case 3: return [2 /*return*/, result]; | ||
@@ -53,9 +56,10 @@ case 4: | ||
case 5: | ||
_e.sent(); | ||
_c.sent(); | ||
resolveDuration = Date.now() - resolveStart; | ||
performNextPass = true; | ||
_a = shouldContinue; | ||
return [4 /*yield*/, manager.betweenEachPass({ | ||
return [4 /*yield*/, manager.afterEachPass({ | ||
index: index, | ||
finished: false, | ||
cancelled: false, | ||
renderDuration: renderDuration, | ||
@@ -66,8 +70,9 @@ resolveDuration: resolveDuration, | ||
performNextPass = | ||
_a.apply(void 0, [_e.sent()]) && performNextPass; | ||
if (!betweenEachPass) return [3 /*break*/, 8]; | ||
_a.apply(void 0, [_c.sent()]) && performNextPass; | ||
if (!afterEachPass) return [3 /*break*/, 8]; | ||
_b = shouldContinue; | ||
return [4 /*yield*/, betweenEachPass({ | ||
return [4 /*yield*/, afterEachPass({ | ||
index: index, | ||
finished: false, | ||
cancelled: false, | ||
renderDuration: renderDuration, | ||
@@ -78,9 +83,10 @@ resolveDuration: resolveDuration, | ||
performNextPass = | ||
_b.apply(void 0, [_e.sent()]) && performNextPass; | ||
_e.label = 8; | ||
_b.apply(void 0, [_c.sent()]) && performNextPass; | ||
_c.label = 8; | ||
case 8: | ||
_c = shouldContinue; | ||
return [4 /*yield*/, manager.afterEachPass({ | ||
if (!performNextPass) return [3 /*break*/, 11]; | ||
return [4 /*yield*/, manager.betweenEachPass({ | ||
index: index, | ||
finished: false, | ||
cancelled: false, | ||
renderDuration: renderDuration, | ||
@@ -90,9 +96,8 @@ resolveDuration: resolveDuration, | ||
case 9: | ||
performNextPass = | ||
_c.apply(void 0, [_e.sent()]) && performNextPass; | ||
if (!afterEachPass) return [3 /*break*/, 11]; | ||
_d = shouldContinue; | ||
return [4 /*yield*/, afterEachPass({ | ||
_c.sent(); | ||
if (!betweenEachPass) return [3 /*break*/, 11]; | ||
return [4 /*yield*/, betweenEachPass({ | ||
index: index, | ||
finished: false, | ||
cancelled: false, | ||
renderDuration: renderDuration, | ||
@@ -102,10 +107,7 @@ resolveDuration: resolveDuration, | ||
case 10: | ||
performNextPass = | ||
_d.apply(void 0, [_e.sent()]) && performNextPass; | ||
_e.label = 11; | ||
_c.sent(); | ||
_c.label = 11; | ||
case 11: | ||
if (index + 1 >= maxPasses || !performNextPass) { | ||
return [2 /*return*/, result]; | ||
} | ||
return [2 /*return*/, perform(index + 1)]; | ||
manager.reset(); | ||
return [2 /*return*/, performNextPass ? perform(index + 1) : result]; | ||
} | ||
@@ -112,0 +114,0 @@ }); |
export interface Pass { | ||
index: number; | ||
finished: boolean; | ||
cancelled: boolean; | ||
renderDuration: number; | ||
@@ -5,0 +6,0 @@ resolveDuration: number; |
{ | ||
"name": "@shopify/react-effect", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "A component and set of utilities for performing effects within a universal React app", |
@@ -78,6 +78,6 @@ # `@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. 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. Returning `false` (or a promise for `false`) from this method will bail out of subsequent passes. | ||
- `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, and we are still less than `maxPasses`). 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`, `cancelled` (`maxPasses` reached), `renderDuration` and `resolveDuration` of the just-completed pass. If there is another pass to perform, this method is called **after** `afterEachPass`. | ||
- `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. | ||
@@ -84,0 +84,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
22981
314