@mjhls/mjh-framework 1.0.939-segment-test-v7 → 1.0.939-segment-test-v8
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/cjs/View.js +31 -9
- package/dist/esm/View.js +31 -9
- package/package.json +1 -1
package/dist/cjs/View.js
CHANGED
|
@@ -507,7 +507,7 @@ var Recommended = function Recommended(props) {
|
|
|
507
507
|
// get users traits
|
|
508
508
|
var getSegmentProfile = function () {
|
|
509
509
|
var _ref = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee() {
|
|
510
|
-
var anonymousId, response, data, addTaxonomyName, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
|
|
510
|
+
var anonymousId, response, data, addTaxonomyName, fetchWithTimeout, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
|
|
511
511
|
|
|
512
512
|
return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
|
|
513
513
|
while (1) {
|
|
@@ -529,7 +529,7 @@ var Recommended = function Recommended(props) {
|
|
|
529
529
|
data = _context.sent;
|
|
530
530
|
|
|
531
531
|
if (!(data && data.traits && data.traits.favorite_article_category)) {
|
|
532
|
-
_context.next =
|
|
532
|
+
_context.next = 26;
|
|
533
533
|
break;
|
|
534
534
|
}
|
|
535
535
|
|
|
@@ -551,6 +551,21 @@ var Recommended = function Recommended(props) {
|
|
|
551
551
|
return query;
|
|
552
552
|
};
|
|
553
553
|
|
|
554
|
+
fetchWithTimeout = function fetchWithTimeout(timeout, fn) {
|
|
555
|
+
|
|
556
|
+
return new asyncToGenerator._Promise(function (resolve, reject) {
|
|
557
|
+
// start timeout
|
|
558
|
+
var timeoutID = setTimeout(function () {
|
|
559
|
+
return resolve([]);
|
|
560
|
+
}, timeout);
|
|
561
|
+
// start calculation
|
|
562
|
+
fn().then(function (result) {
|
|
563
|
+
clearTimeout(timeoutID);
|
|
564
|
+
resolve(result);
|
|
565
|
+
});
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
|
|
554
569
|
favoriteCategories = JSON.parse(data.traits.favorite_article_category);
|
|
555
570
|
// grab 3 articles from sanity different from the one currently being read
|
|
556
571
|
|
|
@@ -560,16 +575,23 @@ var Recommended = function Recommended(props) {
|
|
|
560
575
|
params = {
|
|
561
576
|
id: article._id
|
|
562
577
|
};
|
|
563
|
-
_context.next =
|
|
564
|
-
return asyncToGenerator._Promise.all([
|
|
565
|
-
|
|
566
|
-
|
|
578
|
+
_context.next = 17;
|
|
579
|
+
return asyncToGenerator._Promise.all([fetchWithTimeout(1000, function () {
|
|
580
|
+
return client.fetch(articlesQuery, params);
|
|
581
|
+
}), fetchWithTimeout(600, function () {
|
|
582
|
+
return client.fetch(videosQuery, params);
|
|
583
|
+
}), fetchWithTimeout(600, function () {
|
|
584
|
+
return client.fetch(podcastQuery, params);
|
|
585
|
+
})]);
|
|
586
|
+
|
|
587
|
+
case 17:
|
|
567
588
|
_ref2 = _context.sent;
|
|
568
589
|
_ref3 = slicedToArray._slicedToArray(_ref2, 3);
|
|
569
590
|
_articles = _ref3[0];
|
|
570
591
|
videos = _ref3[1];
|
|
571
592
|
podcasts = _ref3[2];
|
|
572
593
|
|
|
594
|
+
if (_articles.length === 0) setLoaded('failed');
|
|
573
595
|
if (_articles) {
|
|
574
596
|
if (videos[0] && _articles[2]) {
|
|
575
597
|
_articles[2] = videos[0];
|
|
@@ -582,13 +604,13 @@ var Recommended = function Recommended(props) {
|
|
|
582
604
|
}
|
|
583
605
|
setArticles(_articles);
|
|
584
606
|
}
|
|
585
|
-
_context.next =
|
|
607
|
+
_context.next = 27;
|
|
586
608
|
break;
|
|
587
609
|
|
|
588
|
-
case
|
|
610
|
+
case 26:
|
|
589
611
|
setLoaded('failed');
|
|
590
612
|
|
|
591
|
-
case
|
|
613
|
+
case 27:
|
|
592
614
|
case 'end':
|
|
593
615
|
return _context.stop();
|
|
594
616
|
}
|
package/dist/esm/View.js
CHANGED
|
@@ -496,7 +496,7 @@ var Recommended = function Recommended(props) {
|
|
|
496
496
|
// get users traits
|
|
497
497
|
var getSegmentProfile = function () {
|
|
498
498
|
var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() {
|
|
499
|
-
var anonymousId, response, data, addTaxonomyName, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
|
|
499
|
+
var anonymousId, response, data, addTaxonomyName, fetchWithTimeout, favoriteCategories, articlesQuery, videosQuery, podcastQuery, params, _ref2, _ref3, _articles, videos, podcasts;
|
|
500
500
|
|
|
501
501
|
return regenerator.wrap(function _callee$(_context) {
|
|
502
502
|
while (1) {
|
|
@@ -518,7 +518,7 @@ var Recommended = function Recommended(props) {
|
|
|
518
518
|
data = _context.sent;
|
|
519
519
|
|
|
520
520
|
if (!(data && data.traits && data.traits.favorite_article_category)) {
|
|
521
|
-
_context.next =
|
|
521
|
+
_context.next = 26;
|
|
522
522
|
break;
|
|
523
523
|
}
|
|
524
524
|
|
|
@@ -540,6 +540,21 @@ var Recommended = function Recommended(props) {
|
|
|
540
540
|
return query;
|
|
541
541
|
};
|
|
542
542
|
|
|
543
|
+
fetchWithTimeout = function fetchWithTimeout(timeout, fn) {
|
|
544
|
+
|
|
545
|
+
return new _Promise(function (resolve, reject) {
|
|
546
|
+
// start timeout
|
|
547
|
+
var timeoutID = setTimeout(function () {
|
|
548
|
+
return resolve([]);
|
|
549
|
+
}, timeout);
|
|
550
|
+
// start calculation
|
|
551
|
+
fn().then(function (result) {
|
|
552
|
+
clearTimeout(timeoutID);
|
|
553
|
+
resolve(result);
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
};
|
|
557
|
+
|
|
543
558
|
favoriteCategories = JSON.parse(data.traits.favorite_article_category);
|
|
544
559
|
// grab 3 articles from sanity different from the one currently being read
|
|
545
560
|
|
|
@@ -549,16 +564,23 @@ var Recommended = function Recommended(props) {
|
|
|
549
564
|
params = {
|
|
550
565
|
id: article._id
|
|
551
566
|
};
|
|
552
|
-
_context.next =
|
|
553
|
-
return _Promise.all([
|
|
554
|
-
|
|
555
|
-
|
|
567
|
+
_context.next = 17;
|
|
568
|
+
return _Promise.all([fetchWithTimeout(1000, function () {
|
|
569
|
+
return client.fetch(articlesQuery, params);
|
|
570
|
+
}), fetchWithTimeout(600, function () {
|
|
571
|
+
return client.fetch(videosQuery, params);
|
|
572
|
+
}), fetchWithTimeout(600, function () {
|
|
573
|
+
return client.fetch(podcastQuery, params);
|
|
574
|
+
})]);
|
|
575
|
+
|
|
576
|
+
case 17:
|
|
556
577
|
_ref2 = _context.sent;
|
|
557
578
|
_ref3 = _slicedToArray(_ref2, 3);
|
|
558
579
|
_articles = _ref3[0];
|
|
559
580
|
videos = _ref3[1];
|
|
560
581
|
podcasts = _ref3[2];
|
|
561
582
|
|
|
583
|
+
if (_articles.length === 0) setLoaded('failed');
|
|
562
584
|
if (_articles) {
|
|
563
585
|
if (videos[0] && _articles[2]) {
|
|
564
586
|
_articles[2] = videos[0];
|
|
@@ -571,13 +593,13 @@ var Recommended = function Recommended(props) {
|
|
|
571
593
|
}
|
|
572
594
|
setArticles(_articles);
|
|
573
595
|
}
|
|
574
|
-
_context.next =
|
|
596
|
+
_context.next = 27;
|
|
575
597
|
break;
|
|
576
598
|
|
|
577
|
-
case
|
|
599
|
+
case 26:
|
|
578
600
|
setLoaded('failed');
|
|
579
601
|
|
|
580
|
-
case
|
|
602
|
+
case 27:
|
|
581
603
|
case 'end':
|
|
582
604
|
return _context.stop();
|
|
583
605
|
}
|