@next-core/brick-kit 2.175.0 → 2.176.0

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.
@@ -1992,6 +1992,23 @@
1992
1992
  }
1993
1993
  })();
1994
1994
  }
1995
+
1996
+ /** After mount, dispatch the change event when an async data is loaded */
1997
+ handleAsyncAfterMount() {
1998
+ this.data.forEach(item => {
1999
+ if (item.type === "free-variable" && item.async) {
2000
+ // An async data always has `loading`
2001
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2002
+ item.loading.then(value => {
2003
+ item.loaded = true;
2004
+ item.value = value;
2005
+ item.eventTarget.dispatchEvent(new CustomEvent(this.eventName, {
2006
+ detail: value
2007
+ }));
2008
+ });
2009
+ }
2010
+ });
2011
+ }
1995
2012
  deferDefine(contextConfs, coreContext, brick) {
1996
2013
  var {
1997
2014
  mergedContext,
@@ -2078,7 +2095,8 @@
2078
2095
  var isTemplateState = !!storyboardContextWrapper.tplContextId;
2079
2096
  var value = getDefinedTemplateState(isTemplateState, contextConf, brick);
2080
2097
  var load = null;
2081
- var isLazyResolve = false;
2098
+ var loading;
2099
+ var resolvePolicy = "eager";
2082
2100
  if (value === undefined) {
2083
2101
  if (contextConf.resolve) {
2084
2102
  yield storyboardContextWrapper.waitForUsedContext(contextConf.resolve.if);
@@ -2096,10 +2114,13 @@
2096
2114
  return _ref.apply(this, arguments);
2097
2115
  };
2098
2116
  }();
2099
- isLazyResolve = contextConf.resolve.lazy;
2100
- if (!isLazyResolve) {
2117
+ // `async` take precedence over `lazy`
2118
+ resolvePolicy = contextConf.resolve.async && !isTemplateState ? "async" : contextConf.resolve.lazy ? "lazy" : "eager";
2119
+ if (resolvePolicy === "eager") {
2101
2120
  value = yield load();
2102
- } else if (isLazyResolve && contextConf.resolve.trigger) {
2121
+ } else if (resolvePolicy === "async") {
2122
+ loading = load();
2123
+ } else if (contextConf.resolve.trigger) {
2103
2124
  var lifecycleName = contextConf.resolve.trigger;
2104
2125
  if (supportContextResolveTriggerBrickLifeCycle.includes(lifecycleName)) {
2105
2126
  var contextNameArray = storyboardContextWrapper.batchTriggerContextsNamesMap.get(lifecycleName) || [];
@@ -2118,14 +2139,14 @@
2118
2139
  return false;
2119
2140
  }
2120
2141
  }
2121
- if ((!load || isLazyResolve) && contextConf.value !== undefined) {
2142
+ if ((!load || resolvePolicy !== "eager") && contextConf.value !== undefined) {
2122
2143
  yield storyboardContextWrapper.waitForUsedContext(contextConf.value);
2123
2144
  // If the context has no resolve, just use its `value`.
2124
2145
  // Or if the resolve is ignored or lazy, use its `value` as a fallback.
2125
2146
  value = computeRealValue(contextConf.value, mergedContext, true);
2126
2147
  }
2127
2148
  }
2128
- resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, load, !isLazyResolve);
2149
+ resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, load, resolvePolicy === "eager", loading, resolvePolicy === "async");
2129
2150
  return true;
2130
2151
  });
2131
2152
  return _resolveNormalStoryboardContext.apply(this, arguments);
@@ -2149,7 +2170,7 @@
2149
2170
  return brick.properties[contextConf.name];
2150
2171
  }
2151
2172
  }
2152
- function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, load, loaded) {
2173
+ function resolveFreeVariableValue(value, contextConf, mergedContext, storyboardContextWrapper, brick, load, loaded, loading, async) {
2153
2174
  var newContext = {
2154
2175
  type: "free-variable",
2155
2176
  value,
@@ -2157,6 +2178,8 @@
2157
2178
  eventTarget: new EventTarget$1(),
2158
2179
  load,
2159
2180
  loaded,
2181
+ loading,
2182
+ async,
2160
2183
  deps: []
2161
2184
  };
2162
2185
  var eventName = storyboardContextWrapper.formContextId ? "formstate.change" : storyboardContextWrapper.tplContextId ? "state.change" : "context.change";
@@ -12063,6 +12086,7 @@
12063
12086
  // See https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/guides/scroll-restoration.md
12064
12087
  window.scrollTo(0, 0);
12065
12088
  if (!failed) {
12089
+ locationContext.storyboardContextWrapper.handleAsyncAfterMount();
12066
12090
  _this3.locationContext.handleBrickBindObserver();
12067
12091
  _this3.locationContext.handlePageLoad();
12068
12092
  _this3.locationContext.handleAnchorLoad();