Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CollectionManager {
- constructor(){
- this.collectionList = {};
- }
- initialize(collections){
- ...
- }
- populate(){
- var collectionObjs = Object.keys(this.collectionList).map(function(key){
- return collectionManager.collectionList[key];
- });
- return Promise.all(collectionObjs.map(function(collection){
- collection.populateVideos();
- }));
- }
- }
- class Collection {
- constructor(data){
- this.collectionInfo = data;
- this.videoArray = [];
- }
- populateVideos(){
- var collectionKey = this.collectionInfo.COLLECTIONID;
- var vChannels = Object.keys(this.collectionInfo.channels);
- return Promise.all(vChannels.map(requestVideos))
- .then(function (results) {
- var videoIdArray = [];
- return videoIdArray = [].concat.apply([], results);
- }).then(function(arrVideoIds){
- var groups = [];
- for (var i = 0; i < arrVideoIds.length; i += 50) {
- groups.push(arrVideoIds.slice(i, i + 50));
- }
- return groups;
- }).then(function(chunkedArrVideoIds){
- return Promise.all(chunkedArrVideoIds.map(requestVideoData)).then(function (results) {
- var videoTileArray = [].concat.apply([], results);
- collectionManager.collectionList[collectionKey].videoArray = videoTileArray;
- return videoTileArray;
- });
- });
- }
- displayCollection(){
- console.log(this.collectionInfo.COLLECTIONID);
- console.log(collectionManager.collectionList);
- console.log(collectionManager.collectionList[1]);
- console.log(collectionManager.collectionList[1].videoArray);
- collectionManager.populate().then(
- function(){
- collectionManager.displayCollections()
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement