@mjhls/mjh-framework 1.0.939-segment-test-v7 → 1.0.939-segment-test-v9
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 +34 -9
- package/dist/esm/View.js +34 -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) {
|
|
@@ -528,8 +528,11 @@ var Recommended = function Recommended(props) {
|
|
|
528
528
|
case 6:
|
|
529
529
|
data = _context.sent;
|
|
530
530
|
|
|
531
|
+
|
|
532
|
+
console.log('persona result:', data);
|
|
533
|
+
|
|
531
534
|
if (!(data && data.traits && data.traits.favorite_article_category)) {
|
|
532
|
-
_context.next =
|
|
535
|
+
_context.next = 27;
|
|
533
536
|
break;
|
|
534
537
|
}
|
|
535
538
|
|
|
@@ -551,6 +554,21 @@ var Recommended = function Recommended(props) {
|
|
|
551
554
|
return query;
|
|
552
555
|
};
|
|
553
556
|
|
|
557
|
+
fetchWithTimeout = function fetchWithTimeout(timeout, fn) {
|
|
558
|
+
|
|
559
|
+
return new asyncToGenerator._Promise(function (resolve, reject) {
|
|
560
|
+
// start timeout
|
|
561
|
+
var timeoutID = setTimeout(function () {
|
|
562
|
+
return resolve([]);
|
|
563
|
+
}, timeout);
|
|
564
|
+
// start calculation
|
|
565
|
+
fn().then(function (result) {
|
|
566
|
+
clearTimeout(timeoutID);
|
|
567
|
+
resolve(result);
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
|
|
554
572
|
favoriteCategories = JSON.parse(data.traits.favorite_article_category);
|
|
555
573
|
// grab 3 articles from sanity different from the one currently being read
|
|
556
574
|
|
|
@@ -560,16 +578,23 @@ var Recommended = function Recommended(props) {
|
|
|
560
578
|
params = {
|
|
561
579
|
id: article._id
|
|
562
580
|
};
|
|
563
|
-
_context.next =
|
|
564
|
-
return asyncToGenerator._Promise.all([
|
|
565
|
-
|
|
566
|
-
|
|
581
|
+
_context.next = 18;
|
|
582
|
+
return asyncToGenerator._Promise.all([fetchWithTimeout(1000, function () {
|
|
583
|
+
return client.fetch(articlesQuery, params);
|
|
584
|
+
}), fetchWithTimeout(800, function () {
|
|
585
|
+
return client.fetch(videosQuery, params);
|
|
586
|
+
}), fetchWithTimeout(800, function () {
|
|
587
|
+
return client.fetch(podcastQuery, params);
|
|
588
|
+
})]);
|
|
589
|
+
|
|
590
|
+
case 18:
|
|
567
591
|
_ref2 = _context.sent;
|
|
568
592
|
_ref3 = slicedToArray._slicedToArray(_ref2, 3);
|
|
569
593
|
_articles = _ref3[0];
|
|
570
594
|
videos = _ref3[1];
|
|
571
595
|
podcasts = _ref3[2];
|
|
572
596
|
|
|
597
|
+
if (_articles.length === 0) setLoaded('failed');
|
|
573
598
|
if (_articles) {
|
|
574
599
|
if (videos[0] && _articles[2]) {
|
|
575
600
|
_articles[2] = videos[0];
|
|
@@ -582,13 +607,13 @@ var Recommended = function Recommended(props) {
|
|
|
582
607
|
}
|
|
583
608
|
setArticles(_articles);
|
|
584
609
|
}
|
|
585
|
-
_context.next =
|
|
610
|
+
_context.next = 28;
|
|
586
611
|
break;
|
|
587
612
|
|
|
588
|
-
case
|
|
613
|
+
case 27:
|
|
589
614
|
setLoaded('failed');
|
|
590
615
|
|
|
591
|
-
case
|
|
616
|
+
case 28:
|
|
592
617
|
case 'end':
|
|
593
618
|
return _context.stop();
|
|
594
619
|
}
|
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) {
|
|
@@ -517,8 +517,11 @@ var Recommended = function Recommended(props) {
|
|
|
517
517
|
case 6:
|
|
518
518
|
data = _context.sent;
|
|
519
519
|
|
|
520
|
+
|
|
521
|
+
console.log('persona result:', data);
|
|
522
|
+
|
|
520
523
|
if (!(data && data.traits && data.traits.favorite_article_category)) {
|
|
521
|
-
_context.next =
|
|
524
|
+
_context.next = 27;
|
|
522
525
|
break;
|
|
523
526
|
}
|
|
524
527
|
|
|
@@ -540,6 +543,21 @@ var Recommended = function Recommended(props) {
|
|
|
540
543
|
return query;
|
|
541
544
|
};
|
|
542
545
|
|
|
546
|
+
fetchWithTimeout = function fetchWithTimeout(timeout, fn) {
|
|
547
|
+
|
|
548
|
+
return new _Promise(function (resolve, reject) {
|
|
549
|
+
// start timeout
|
|
550
|
+
var timeoutID = setTimeout(function () {
|
|
551
|
+
return resolve([]);
|
|
552
|
+
}, timeout);
|
|
553
|
+
// start calculation
|
|
554
|
+
fn().then(function (result) {
|
|
555
|
+
clearTimeout(timeoutID);
|
|
556
|
+
resolve(result);
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
};
|
|
560
|
+
|
|
543
561
|
favoriteCategories = JSON.parse(data.traits.favorite_article_category);
|
|
544
562
|
// grab 3 articles from sanity different from the one currently being read
|
|
545
563
|
|
|
@@ -549,16 +567,23 @@ var Recommended = function Recommended(props) {
|
|
|
549
567
|
params = {
|
|
550
568
|
id: article._id
|
|
551
569
|
};
|
|
552
|
-
_context.next =
|
|
553
|
-
return _Promise.all([
|
|
554
|
-
|
|
555
|
-
|
|
570
|
+
_context.next = 18;
|
|
571
|
+
return _Promise.all([fetchWithTimeout(1000, function () {
|
|
572
|
+
return client.fetch(articlesQuery, params);
|
|
573
|
+
}), fetchWithTimeout(800, function () {
|
|
574
|
+
return client.fetch(videosQuery, params);
|
|
575
|
+
}), fetchWithTimeout(800, function () {
|
|
576
|
+
return client.fetch(podcastQuery, params);
|
|
577
|
+
})]);
|
|
578
|
+
|
|
579
|
+
case 18:
|
|
556
580
|
_ref2 = _context.sent;
|
|
557
581
|
_ref3 = _slicedToArray(_ref2, 3);
|
|
558
582
|
_articles = _ref3[0];
|
|
559
583
|
videos = _ref3[1];
|
|
560
584
|
podcasts = _ref3[2];
|
|
561
585
|
|
|
586
|
+
if (_articles.length === 0) setLoaded('failed');
|
|
562
587
|
if (_articles) {
|
|
563
588
|
if (videos[0] && _articles[2]) {
|
|
564
589
|
_articles[2] = videos[0];
|
|
@@ -571,13 +596,13 @@ var Recommended = function Recommended(props) {
|
|
|
571
596
|
}
|
|
572
597
|
setArticles(_articles);
|
|
573
598
|
}
|
|
574
|
-
_context.next =
|
|
599
|
+
_context.next = 28;
|
|
575
600
|
break;
|
|
576
601
|
|
|
577
|
-
case
|
|
602
|
+
case 27:
|
|
578
603
|
setLoaded('failed');
|
|
579
604
|
|
|
580
|
-
case
|
|
605
|
+
case 28:
|
|
581
606
|
case 'end':
|
|
582
607
|
return _context.stop();
|
|
583
608
|
}
|