Last active
December 24, 2015 07:49
-
-
Save davidworkman9/6766259 to your computer and use it in GitHub Desktop.
Extension of my random on interval demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template.randomImg1.img = function () { | |
return imgs.findOne({_id: Session.get('randomImg1') }); | |
}; | |
Template.randomImg2.img = function () { | |
return imgs.findOne({_id: Session.get('randomImg2') }); | |
}; | |
Template.randomImg3.img = function () { | |
return imgs.findOne({_id: Session.get('randomImg4') }); | |
}; | |
Template.randomImg4.img = function () { | |
return imgs.findOne({_id: Session.get('randomImg4') }); | |
}; | |
SetInterval(function () { | |
Meteor.methods('getRandomImg', function (err, _id) { | |
Meteor.subscribe('imgById', _id); | |
Session.set('randomImg2', _id); | |
}); | |
}, 5 * 1000); | |
SetInterval(function () { | |
Meteor.methods('getRandomImg', function (err, _id) { | |
Meteor.subscribe('imgById', _id); | |
Session.set('randomImg3', _id); | |
}); | |
}, 30 * 1000); | |
SetInterval(function () { | |
Meteor.methods('getRandomImg', function (err, _id) { | |
Meteor.subscribe('imgById', _id); | |
Session.set('randomImg4', _id); | |
}); | |
}, 10 * 1000); | |
SetInterval(function () { | |
Meteor.methods('getRandomImg', function (err, _id) { | |
Meteor.subscribe('imgById', _id); | |
Session.set('randomImg1', _id); | |
}); | |
}, 15 * 1000); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var randomWithinRange = function randomWithinRange (min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
}; | |
Meteor.methods({ | |
'getRandomImg': function () { | |
var numToSkip = randomWithinRange(0, imgs.find().count()); | |
return imgs.findOne({}, {limit: 1, skip: numToSkip})._id; | |
} | |
}); | |
Meteor.publish('imgById', function (_id) { | |
check(_id, Number); | |
return imgs.find({_id: _id}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment