@magicdoor/magic-use-case-react 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/index.js +6 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @magicdoor/magic-use-case-react
|
|
2
2
|
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Close a use case's mutation window on the scope it opened, rather than on
|
|
8
|
+
whichever scope is current when it finishes.
|
|
9
|
+
|
|
10
|
+
A run can outlive the scope it started in — a detached one, or one still in
|
|
11
|
+
flight when a request ends. Resolving the scope again at closing time made that
|
|
12
|
+
run decrement a scope it never belonged to, shutting a window another run was
|
|
13
|
+
depending on: the second run's next write to application state failed with
|
|
14
|
+
"Cannot set property … outside a use case" even though it was squarely inside
|
|
15
|
+
`runLogic`. On a server it was worse than a wrong count, since resolving a scope
|
|
16
|
+
with no request in progress throws, and it threw from inside a `finally`.
|
|
17
|
+
|
|
3
18
|
## 0.1.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -123,21 +123,22 @@ function onNavigation(handler) {
|
|
|
123
123
|
return () => emitter.unregisterFromNavigation(wrapper);
|
|
124
124
|
}
|
|
125
125
|
function openMutationWindow() {
|
|
126
|
-
currentScope().openMutationWindows += 1;
|
|
127
|
-
}
|
|
128
|
-
function closeMutationWindow() {
|
|
129
126
|
const scope = currentScope();
|
|
127
|
+
scope.openMutationWindows += 1;
|
|
128
|
+
return scope;
|
|
129
|
+
}
|
|
130
|
+
function closeMutationWindow(scope) {
|
|
130
131
|
scope.openMutationWindows = Math.max(0, scope.openMutationWindows - 1);
|
|
131
132
|
}
|
|
132
133
|
function isMutationWindowOpen() {
|
|
133
134
|
return currentScope().openMutationWindows > 0;
|
|
134
135
|
}
|
|
135
136
|
async function withMutationWindow(run) {
|
|
136
|
-
openMutationWindow();
|
|
137
|
+
const scope = openMutationWindow();
|
|
137
138
|
try {
|
|
138
139
|
return await run();
|
|
139
140
|
} finally {
|
|
140
|
-
closeMutationWindow();
|
|
141
|
+
closeMutationWindow(scope);
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
function assertMutationWindowOpen(operation) {
|
package/package.json
CHANGED