brew-js-react 0.7.3 → 0.7.4

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/hooks.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type SetQueryParamAction<T> = Partial<T> | ((prev: Readonly<T>) => Partial<T>);
2
2
 
3
- export const ViewStateContainer: React.FC;
3
+ export const ViewStateContainer: React.FC<React.PropsWithChildren<{}>>;
4
4
 
5
5
  /**
6
6
  * Returns if the app has completed initialization, and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brew-js-react",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/view.js CHANGED
@@ -2,7 +2,7 @@ import { Component, createContext, createElement, useContext, useLayoutEffect }
2
2
  import { createAsyncScope, useAsync } from "zeta-dom-react";
3
3
  import dom, { reportError } from "zeta-dom/dom";
4
4
  import { ZetaEventContainer } from "zeta-dom/events";
5
- import { always, any, arrRemove, catchAsync, createPrivateStore, defineObservableProperty, defineOwnProperty, definePrototype, delay, each, exclude, executeOnce, extend, fill, freeze, grep, isArray, isFunction, isPlainObject, isThenable, isUndefinedOrNull, keys, makeArray, map, noop, pick, randomId, setImmediate, single, throwNotFunction, watch } from "zeta-dom/util";
5
+ import { always, any, arrRemove, catchAsync, combineFn, createPrivateStore, defineObservableProperty, defineOwnProperty, definePrototype, delay, each, exclude, executeOnce, extend, fill, freeze, grep, hasOwnProperty, isArray, isFunction, isPlainObject, isThenable, isUndefinedOrNull, keys, makeArray, map, noop, pick, randomId, setImmediate, single, throwNotFunction, watch } from "zeta-dom/util";
6
6
  import { animateIn, animateOut } from "brew-js/anim";
7
7
  import { toQueryString } from "brew-js/util/common";
8
8
  import { removeQueryAndHash } from "brew-js/util/path";
@@ -30,9 +30,7 @@ onAppInit(function () {
30
30
  event = e;
31
31
  (function updateViewRecursive(next) {
32
32
  each(next.children, function (i, v) {
33
- e.waitFor(new Promise(function (resolve) {
34
- v.forceUpdate(resolve);
35
- }).then(function () {
33
+ e.waitFor(v.renderAsync().then(function () {
36
34
  updateViewRecursive(v);
37
35
  }));
38
36
  });
@@ -148,6 +146,7 @@ definePrototype(ErrorBoundary, Component, {
148
146
  function ViewContainer() {
149
147
  Component.apply(this, arguments);
150
148
  this.views = [];
149
+ this.dispose = new Set();
151
150
  }
152
151
  ViewContainer.contextType = StateContext;
153
152
 
@@ -165,6 +164,7 @@ definePrototype(ViewContainer, Component, {
165
164
  setImmediate(function () {
166
165
  if (self.currentContext && !self.currentContext.active) {
167
166
  self.unmountView();
167
+ combineFn(self.dispose)();
168
168
  }
169
169
  });
170
170
  };
@@ -179,6 +179,16 @@ definePrototype(ViewContainer, Component, {
179
179
  this.currentContext = context;
180
180
  (this.props.rootProps.ref || {}).current = context;
181
181
  },
182
+ renderAsync: function () {
183
+ var self = this;
184
+ return new Promise(function (resolve) {
185
+ self.dispose.add(resolve);
186
+ self.forceUpdate(function () {
187
+ self.dispose.delete(resolve);
188
+ resolve();
189
+ });
190
+ });
191
+ },
182
192
  render: function () {
183
193
  /** @type {any} */
184
194
  var self = this;
@@ -232,9 +242,7 @@ definePrototype(ViewContainer, Component, {
232
242
  app.emit('pageleave', element, { pathname: context.page.path, view: V }, true);
233
243
  return animateOut(element, 'show').then(function () {
234
244
  self.views[0] = null;
235
- return new Promise(function (resolve) {
236
- self.forceUpdate(resolve);
237
- });
245
+ return self.renderAsync();
238
246
  });
239
247
  });
240
248
  always(promise || delay(), function () {
@@ -273,31 +281,26 @@ function normalizePart(value, part) {
273
281
  function getCurrentParams(view, params) {
274
282
  var state = routeMap.get(view);
275
283
  if (!state.maxParams) {
276
- var matchers = exclude(state.matchers, ['remainingSegments']);
284
+ var maxParams = {};
277
285
  var matched = map(app.routes, function (v) {
278
286
  var route = app.parseRoute(v);
279
- var matched = route.length && !any(matchers, function (v, i) {
280
- var pos = route.params[i];
281
- return (v ? !(pos >= 0) : pos < route.minLength) || (!isFunction(v) && !route.match(i, v));
287
+ var routeParams = route.params;
288
+ var params = {};
289
+ var invalid = single(routeParams, (v, i) => {
290
+ if (usedParams[i] && !state.matchers[i]) {
291
+ return v < route.minLength;
292
+ }
293
+ params[i] = true;
294
+ }) || single(state.matchers, function (v, i) {
295
+ return i !== 'remainingSegments' && !(isFunction(v) ? hasOwnProperty(routeParams, i) : v ? route.match(i, v) : routeParams[i] >= route.minLength);
282
296
  });
283
- return matched ? route : null;
297
+ return invalid ? null : extend(maxParams, params) && route;
298
+ });
299
+ var last = matched.slice(-1)[0] || {};
300
+ state.maxParams = ['remainingSegments'].concat(keys(maxParams));
301
+ state.minParams = map(last.params, function (v, i) {
302
+ return state.params[i] || v >= last.minLength ? null : i;
284
303
  });
285
- if (matched[1]) {
286
- matched = grep(matched, function (v) {
287
- return !single(v.params, function (v, i) {
288
- return usedParams[i] && !matchers[i];
289
- });
290
- });
291
- }
292
- if (matched[0]) {
293
- var last = matched.slice(-1)[0];
294
- state.maxParams = keys(extend.apply(0, [{ remainingSegments: true }].concat(matched.map(function (v) {
295
- return v.params;
296
- }))));
297
- state.minParams = map(last.params, function (v, i) {
298
- return state.params[i] || v >= last.minLength ? null : i;
299
- });
300
- }
301
304
  }
302
305
  return extend(pick(app.route, state.minParams), params && pick(params, state.maxParams), state.params);
303
306
  }