brew-js-react 0.2.5 → 0.2.6

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.
@@ -547,32 +547,22 @@ var sortedViews = [];
547
547
  var StateContext = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createContext(Object.freeze({
548
548
  active: true
549
549
  }));
550
- var stateId;
551
550
 
552
551
  function ViewContainer() {
553
- /** @type {any} */
554
- var self = this;
555
- external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(self, arguments);
556
- self.mounted = false;
557
-
558
- if (!stateId) {
559
- stateId = history.state;
560
- app_app.on('navigate', function () {
561
- stateId = history.state;
562
- });
563
- }
564
-
565
- self.componentWillUnmount = app_app.on('navigate', function () {
566
- if (self.mounted && self.getViewComponent()) {
567
- self.isForceUpdate = true;
568
- self.forceUpdate();
569
- }
570
- });
552
+ external_commonjs_react_commonjs2_react_amd_react_root_React_.Component.apply(this, arguments);
553
+ this.stateId = history.state;
571
554
  }
572
555
 
573
556
  definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react_root_React_.Component, {
574
557
  componentDidMount: function componentDidMount() {
575
- this.mounted = true;
558
+ /** @type {any} */
559
+ var self = this;
560
+ self.componentWillUnmount = combineFn(watch(app_app.route, function () {
561
+ self.setActive(self.getViewComponent() === self.currentViewComponent);
562
+ }), app_app.on('beforepageload', function () {
563
+ self.stateId = history.state;
564
+ self.forceUpdate();
565
+ }));
576
566
  },
577
567
  componentDidCatch: function componentDidCatch(error) {
578
568
  zeta_dom_dom.emit('error', this.parentElement || view_root, {
@@ -582,22 +572,32 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
582
572
  render: function render() {
583
573
  /** @type {any} */
584
574
  var self = this;
585
- var resolve;
586
- var promise = new Promise(function (_resolve) {
587
- resolve = _resolve;
588
- });
575
+
576
+ if (history.state !== self.stateId) {
577
+ return self.lastChild || null;
578
+ }
579
+
589
580
  var V = self.getViewComponent();
590
581
 
582
+ if (V) {
583
+ // ensure the current path actually corresponds to the matched view
584
+ // when some views are not included in the list of allowed views
585
+ var targetPath = linkTo(V, getCurrentParams(V, true));
586
+
587
+ if (targetPath !== removeQueryAndHash(app_app.path)) {
588
+ app_app.navigate(targetPath, true);
589
+ }
590
+ }
591
+
591
592
  if (V && V !== self.currentViewComponent) {
592
- self.currentViewComponent = V;
593
+ var prevElement = self.currentElement;
593
594
 
594
- if (self.currentView && self.currentElement) {
595
- var prevPath = self.currentPath;
596
- var prevElement = self.currentElement;
595
+ if (prevElement) {
596
+ self.setActive(false);
597
597
  self.prevView = self.currentView;
598
598
  self.currentElement = undefined;
599
599
  app_app.emit('pageleave', prevElement, {
600
- pathname: prevPath
600
+ pathname: self.currentPath
601
601
  }, true);
602
602
  animateOut(prevElement, 'show').then(function () {
603
603
  self.prevView = undefined;
@@ -605,13 +605,17 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
605
605
  });
606
606
  }
607
607
 
608
- var providerProps = {
609
- key: routeMap.get(V).id,
610
- value: {
611
- view: V
612
- }
608
+ var resolve;
609
+ var promise = new Promise(function (resolve_) {
610
+ resolve = resolve_;
611
+ });
612
+ var state = {
613
+ view: V
613
614
  };
614
- var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider, providerProps, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewStateContainer, null, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(V, {
615
+ var view = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(StateContext.Provider, {
616
+ key: routeMap.get(V).id,
617
+ value: state
618
+ }, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(ViewStateContainer, null, /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(V, {
615
619
  rootProps: self.props.rootProps,
616
620
  onComponentLoaded: function onComponentLoaded(element) {
617
621
  self.currentElement = element;
@@ -625,40 +629,22 @@ definePrototype(ViewContainer, external_commonjs_react_commonjs2_react_amd_react
625
629
  });
626
630
  }
627
631
  })));
628
- defineGetterProperty(providerProps.value, 'active', function () {
629
- return self.currentView === view;
632
+ extend(self, {
633
+ currentPath: app_app.path,
634
+ currentView: view,
635
+ currentViewComponent: V,
636
+ setActive: defineObservableProperty(state, 'active', true, true)
630
637
  });
631
- self.currentPath = app_app.path;
632
- self.currentView = view;
633
- } else {
634
- if (self.isForceUpdate) {
635
- self.isForceUpdate = false;
636
- app_app.emit('pageenter', self.currentElement, {
637
- pathname: app_app.path
638
- }, true);
639
- }
640
-
641
- resolve();
638
+ notifyAsync(self.parentElement || view_root, promise);
642
639
  }
643
640
 
644
- notifyAsync(self.parentElement || view_root, promise);
645
- return /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment, null, self.prevView, self.currentView);
641
+ var child = /*#__PURE__*/external_commonjs_react_commonjs2_react_amd_react_root_React_.createElement(external_commonjs_react_commonjs2_react_amd_react_root_React_.Fragment, null, self.prevView, self.currentView);
642
+ self.lastChild = child;
643
+ return child;
646
644
  },
647
645
  getViewComponent: function getViewComponent() {
648
646
  var props = this.props;
649
- var matched = any(props.views, isViewMatched) || props.defaultView;
650
-
651
- if (history.state === stateId) {
652
- // ensure the current path actually corresponds to the matched view
653
- // when some views are not included in the list of allowed views
654
- var targetPath = linkTo(matched, getCurrentParams(matched, true));
655
-
656
- if (targetPath !== removeQueryAndHash(app_app.path)) {
657
- app_app.navigate(targetPath, true);
658
- }
659
- }
660
-
661
- return matched;
647
+ return any(props.views, isViewMatched) || props.defaultView;
662
648
  }
663
649
  });
664
650
 
@@ -846,9 +832,13 @@ function useRouteParam(name, defaultValue) {
846
832
  var setValue = function setValue() {
847
833
  var current = route[name] || '';
848
834
 
849
- if (container.active && current !== ref.current) {
850
- ref.current = current;
851
- forceUpdate({});
835
+ if (current !== ref.current) {
836
+ if (container.active) {
837
+ ref.current = current;
838
+ forceUpdate({});
839
+ } else {
840
+ watch(container, 'active', setValue);
841
+ }
852
842
  }
853
843
  }; // route parameter might be changed after state initialization and before useEffect hook is called
854
844