@next-core/brick-kit 2.135.0 → 2.136.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 +30 -0
- package/dist/index.bundle.js +82 -62
- package/dist/index.bundle.js.map +1 -1
- package/dist/index.esm.js +82 -62
- package/dist/index.esm.js.map +1 -1
- package/dist/types/core/StoryboardContext.d.ts +2 -2
- package/dist/types/core/StoryboardContext.d.ts.map +1 -1
- package/dist/types/internal/bindListeners.d.ts +2 -1
- package/dist/types/internal/bindListeners.d.ts.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,36 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.136.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.136.0...@next-core/brick-kit@2.136.1) (2022-09-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* fix missing runtime brick in event callback ([a5b70be](https://github.com/easyops-cn/next-core/commit/a5b70be68bc6a856b78992320518d0a0e6a41128))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [2.136.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.135.1...@next-core/brick-kit@2.136.0) (2022-09-05)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* support context/state load/refresh callback ([4dfdd8b](https://github.com/easyops-cn/next-core/commit/4dfdd8bc8e91430a99857154237bae290c685329))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [2.135.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.135.0...@next-core/brick-kit@2.135.1) (2022-09-02)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package @next-core/brick-kit
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
6
36
|
# [2.135.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.134.2...@next-core/brick-kit@2.135.0) (2022-09-02)
|
|
7
37
|
|
|
8
38
|
|
package/dist/index.bundle.js
CHANGED
|
@@ -1971,7 +1971,7 @@
|
|
|
1971
1971
|
return (_this$data$get = this.data.get(name)) === null || _this$data$get === void 0 ? void 0 : _this$data$get.value;
|
|
1972
1972
|
}
|
|
1973
1973
|
|
|
1974
|
-
updateValue(name, value, method) {
|
|
1974
|
+
updateValue(name, value, method, callback) {
|
|
1975
1975
|
var _item$eventTarget2;
|
|
1976
1976
|
|
|
1977
1977
|
if (!this.data.has(name)) {
|
|
@@ -1994,36 +1994,58 @@
|
|
|
1994
1994
|
// eslint-disable-next-line no-console
|
|
1995
1995
|
console.error("Unexpected storyboard context \"".concat(name, "\", expected \"free-variable\", received \"").concat(item.type, "\"."));
|
|
1996
1996
|
return;
|
|
1997
|
-
}
|
|
1998
|
-
|
|
1997
|
+
}
|
|
1999
1998
|
|
|
2000
1999
|
if (method === "refresh" || method === "load") {
|
|
2001
2000
|
if (!item.load) {
|
|
2002
2001
|
throw new Error("You can not ".concat(method, " the storyboard context \"").concat(name, "\" which has no resolve."));
|
|
2003
2002
|
}
|
|
2004
2003
|
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2004
|
+
var promise;
|
|
2005
|
+
|
|
2006
|
+
if (method === "load") {
|
|
2007
|
+
// Try to reuse previous request when calling `load`.
|
|
2008
|
+
if (item.loaded) {
|
|
2009
|
+
promise = Promise.resolve(item.value);
|
|
2010
|
+
} else if (item.loading) {
|
|
2011
|
+
promise = item.loading;
|
|
2012
|
+
}
|
|
2008
2013
|
}
|
|
2009
2014
|
|
|
2010
|
-
|
|
2015
|
+
if (!promise) {
|
|
2016
|
+
promise = item.loading = item.load(_objectSpread__default["default"]({
|
|
2017
|
+
cache: method === "load" ? "default" : "reload"
|
|
2018
|
+
}, value)); // Do not use the chained promise, since the callbacks need the original promise.
|
|
2011
2019
|
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2020
|
+
promise.then(val => {
|
|
2021
|
+
var _item$eventTarget;
|
|
2022
|
+
|
|
2023
|
+
item.loaded = true;
|
|
2024
|
+
item.value = val;
|
|
2025
|
+
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
|
|
2026
|
+
detail: item.value
|
|
2027
|
+
}));
|
|
2028
|
+
}, err => {
|
|
2029
|
+
// Let users to override error handling.
|
|
2030
|
+
if (!(callback !== null && callback !== void 0 && callback.error)) {
|
|
2031
|
+
handleHttpError(err);
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
if (callback) {
|
|
2037
|
+
var callbackFactory = eventCallbackFactory(callback, () => this.getResolveOptions(_internalApiGetCurrentContext()).mergedContext, null);
|
|
2038
|
+
promise.then(val => {
|
|
2039
|
+
callbackFactory("success")({
|
|
2040
|
+
value: val
|
|
2041
|
+
});
|
|
2042
|
+
callbackFactory("finally")();
|
|
2043
|
+
}, err => {
|
|
2044
|
+
callbackFactory("error")(err);
|
|
2045
|
+
callbackFactory("finally")();
|
|
2046
|
+
});
|
|
2047
|
+
}
|
|
2016
2048
|
|
|
2017
|
-
item.loading = false;
|
|
2018
|
-
item.loaded = true;
|
|
2019
|
-
item.value = val;
|
|
2020
|
-
(_item$eventTarget = item.eventTarget) === null || _item$eventTarget === void 0 ? void 0 : _item$eventTarget.dispatchEvent(new CustomEvent(this.tplContextId ? "state.change" : "context.change", {
|
|
2021
|
-
detail: item.value
|
|
2022
|
-
}));
|
|
2023
|
-
}, err => {
|
|
2024
|
-
item.loading = false;
|
|
2025
|
-
handleHttpError(err);
|
|
2026
|
-
});
|
|
2027
2049
|
return;
|
|
2028
2050
|
}
|
|
2029
2051
|
|
|
@@ -6310,12 +6332,12 @@
|
|
|
6310
6332
|
case "context.replace":
|
|
6311
6333
|
case "context.refresh":
|
|
6312
6334
|
case "context.load":
|
|
6313
|
-
return builtinContextListenerFactory(method, handler.args, handler, context);
|
|
6335
|
+
return builtinContextListenerFactory(method, handler.args, handler, handler.callback, context);
|
|
6314
6336
|
|
|
6315
6337
|
case "state.update":
|
|
6316
6338
|
case "state.refresh":
|
|
6317
6339
|
case "state.load":
|
|
6318
|
-
return builtinStateListenerFactory(method, handler.args, handler, context);
|
|
6340
|
+
return builtinStateListenerFactory(method, handler.args, handler, handler.callback, context);
|
|
6319
6341
|
|
|
6320
6342
|
case "tpl.dispatchEvent":
|
|
6321
6343
|
return builtinTplDispatchEventFactory(handler.args, handler, context);
|
|
@@ -6444,7 +6466,7 @@
|
|
|
6444
6466
|
};
|
|
6445
6467
|
}
|
|
6446
6468
|
|
|
6447
|
-
function builtinContextListenerFactory(method, args, ifContainer, context) {
|
|
6469
|
+
function builtinContextListenerFactory(method, args, ifContainer, callback, context) {
|
|
6448
6470
|
return function (event) {
|
|
6449
6471
|
if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
|
|
6450
6472
|
event
|
|
@@ -6455,11 +6477,11 @@
|
|
|
6455
6477
|
var storyboardContext = _internalApiGetStoryboardContextWrapper();
|
|
6456
6478
|
|
|
6457
6479
|
var [name, value] = argsFactory(args, context, event);
|
|
6458
|
-
storyboardContext.updateValue(name, value, method);
|
|
6480
|
+
storyboardContext.updateValue(name, value, method, callback);
|
|
6459
6481
|
};
|
|
6460
6482
|
}
|
|
6461
6483
|
|
|
6462
|
-
function builtinStateListenerFactory(method, args, ifContainer, context) {
|
|
6484
|
+
function builtinStateListenerFactory(method, args, ifContainer, callback, context) {
|
|
6463
6485
|
return function (event) {
|
|
6464
6486
|
if (!looseCheckIf(ifContainer, _objectSpread__default["default"](_objectSpread__default["default"]({}, context), {}, {
|
|
6465
6487
|
event
|
|
@@ -6469,7 +6491,7 @@
|
|
|
6469
6491
|
|
|
6470
6492
|
var tplContext = getTplContext(context.tplContextId);
|
|
6471
6493
|
var [name, value] = argsFactory(args, context, event);
|
|
6472
|
-
tplContext.state.updateValue(name, value, method === "update" ? "replace" : method);
|
|
6494
|
+
tplContext.state.updateValue(name, value, method === "update" ? "replace" : method, callback);
|
|
6473
6495
|
};
|
|
6474
6496
|
}
|
|
6475
6497
|
|
|
@@ -6670,13 +6692,39 @@
|
|
|
6670
6692
|
};
|
|
6671
6693
|
}
|
|
6672
6694
|
|
|
6695
|
+
function eventCallbackFactory(callback, getContext, runtimeBrick) {
|
|
6696
|
+
return function callbackFactory(type) {
|
|
6697
|
+
return function (result) {
|
|
6698
|
+
if (callback !== null && callback !== void 0 && callback[type]) {
|
|
6699
|
+
try {
|
|
6700
|
+
var event = new CustomEvent("callback.".concat(type), {
|
|
6701
|
+
detail: result
|
|
6702
|
+
});
|
|
6703
|
+
var context = getContext();
|
|
6704
|
+
[].concat(callback[type]).forEach(eachHandler => {
|
|
6705
|
+
listenerFactory(eachHandler, context, runtimeBrick)(event);
|
|
6706
|
+
});
|
|
6707
|
+
} catch (err) {
|
|
6708
|
+
// Do not throw errors in `callback.success` or `callback.progress`,
|
|
6709
|
+
// to avoid the following triggering of `callback.error`.
|
|
6710
|
+
// eslint-disable-next-line
|
|
6711
|
+
console.error(err);
|
|
6712
|
+
}
|
|
6713
|
+
} else if (type === "error") {
|
|
6714
|
+
// eslint-disable-next-line
|
|
6715
|
+
console.error("Unhandled callback error:", result);
|
|
6716
|
+
}
|
|
6717
|
+
};
|
|
6718
|
+
};
|
|
6719
|
+
}
|
|
6720
|
+
|
|
6673
6721
|
function brickCallback(_x2, _x3, _x4, _x5, _x6, _x7, _x8) {
|
|
6674
6722
|
return _brickCallback.apply(this, arguments);
|
|
6675
6723
|
}
|
|
6676
6724
|
|
|
6677
6725
|
function _brickCallback() {
|
|
6678
6726
|
_brickCallback = _asyncToGenerator__default["default"](function* (target, handler, method, context, runtimeBrick, event, options) {
|
|
6679
|
-
var
|
|
6727
|
+
var _poll;
|
|
6680
6728
|
|
|
6681
6729
|
if (typeof target[method] !== "function") {
|
|
6682
6730
|
// eslint-disable-next-line no-console
|
|
@@ -6703,45 +6751,17 @@
|
|
|
6703
6751
|
};
|
|
6704
6752
|
}();
|
|
6705
6753
|
|
|
6706
|
-
|
|
6707
|
-
success,
|
|
6708
|
-
error,
|
|
6709
|
-
finally: finallyHook,
|
|
6710
|
-
progress
|
|
6711
|
-
} = (_handler$callback = handler.callback) !== null && _handler$callback !== void 0 ? _handler$callback : {};
|
|
6712
|
-
|
|
6713
|
-
if (!(success || error || finallyHook || progress)) {
|
|
6754
|
+
if (!handler.callback) {
|
|
6714
6755
|
task();
|
|
6715
6756
|
return;
|
|
6716
6757
|
}
|
|
6717
6758
|
|
|
6718
|
-
var callbackFactory = (
|
|
6719
|
-
if (specificHandler) {
|
|
6720
|
-
try {
|
|
6721
|
-
var _event = new CustomEvent(eventType, {
|
|
6722
|
-
detail: result
|
|
6723
|
-
});
|
|
6724
|
-
|
|
6725
|
-
[].concat(specificHandler).forEach(eachHandler => {
|
|
6726
|
-
listenerFactory(eachHandler, context, runtimeBrick)(_event);
|
|
6727
|
-
});
|
|
6728
|
-
} catch (err) {
|
|
6729
|
-
// Do not throw errors in `callback.success` or `callback.progress`,
|
|
6730
|
-
// to avoid the following triggering of `callback.error`.
|
|
6731
|
-
// eslint-disable-next-line
|
|
6732
|
-
console.error(err);
|
|
6733
|
-
}
|
|
6734
|
-
} else if (eventType === "callback.error") {
|
|
6735
|
-
// eslint-disable-next-line
|
|
6736
|
-
console.error("Unhandled callback error:", result);
|
|
6737
|
-
}
|
|
6738
|
-
};
|
|
6739
|
-
|
|
6759
|
+
var callbackFactory = eventCallbackFactory(handler.callback, () => context, runtimeBrick);
|
|
6740
6760
|
var pollableCallback = {
|
|
6741
|
-
progress: callbackFactory("
|
|
6742
|
-
success: callbackFactory("
|
|
6743
|
-
error: callbackFactory("
|
|
6744
|
-
finally: callbackFactory("
|
|
6761
|
+
progress: callbackFactory("progress"),
|
|
6762
|
+
success: callbackFactory("success"),
|
|
6763
|
+
error: callbackFactory("error"),
|
|
6764
|
+
finally: callbackFactory("finally")
|
|
6745
6765
|
};
|
|
6746
6766
|
var poll;
|
|
6747
6767
|
|