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.
- package/dist/brew-js-react.js +56 -66
- package/dist/brew-js-react.js.map +1 -1
- package/dist/brew-js-react.min.js +1 -1
- package/dist/brew-js-react.min.js.map +1 -1
- package/hooks.js +8 -4
- package/package.json +2 -2
- package/view.js +223 -234
package/dist/brew-js-react.js
CHANGED
|
@@ -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
|
-
|
|
554
|
-
|
|
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
|
-
|
|
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
|
-
|
|
586
|
-
|
|
587
|
-
|
|
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
|
-
|
|
593
|
+
var prevElement = self.currentElement;
|
|
593
594
|
|
|
594
|
-
if (
|
|
595
|
-
|
|
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:
|
|
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
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
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,
|
|
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
|
-
|
|
629
|
-
|
|
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.
|
|
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
|
-
|
|
645
|
-
|
|
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
|
-
|
|
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 (
|
|
850
|
-
|
|
851
|
-
|
|
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
|
|