Running a function only once on first match
humanaut opened this issue · comments
Hello,
I am testing SimpleStateManager after coming from enquire, as I'm sure a lot of other people are.
With enquire, I can use something called "Setup" which only runs the contents of my match once, the first time it happens. If the match happens 4-5 more times, it doesn't happen again. This has been useful for me sometimes.
I was wondering if SSM has something similar.
I sort of threw something together that mimics this, but I was wondering if there is more accurate or standard way of doing this.
ssm.addState({
id: 'smallScreen2',
maxWidth: 464,
onEnter: function(){
console.log('Resize me!');
},
onLeave: function(){
ssm.removeState('smallScreen2');
}
});
ssm.ready();
Thanks in advance!
Hi, no we don't have this I am afraid, I can add it easy enough though
Thanks Jonathan,
If you are able to, I look forward to seeing it. I don't use it religiously but I have found it useful for certain situations.
Thanks!
Hi,
This feature is avaliable in 2.3.0 which I just published, open a new ticket if you find any bugs with the new feature
to use, add a onFirstRun callback:
ssm.addState({
id: 'tablet',
minWidth: 768,
maxWidth: 991,
onEnter: function(){
document.getElementById('hero').style.backgroundColor = "#f0b958";
},
onFirstRun: function(){
console.log('setup tablet');
}
});
Hope you enjoy using SSM