Okay, so today I wanted to mess around with blinking stuff on a screen, but without all that fancy subscription stuff. Just simple, old-school local storage. Here’s how it went down:
First, I needed a place to store my stuff. I decided to go simple,so created a simple object in the localStorage:
javascript
*(‘myBlinkData’, *({ isVisible: true }));
I’m basically putting a little note in the browser’s storage saying, “Hey, whatever I’m blinking should be visible right now.”
Getting the Party Started
Next, I needed a function to do the actual blinking. I came up with this:
javascript
function blink() {
let data = *(*(‘myBlinkData’));
* = !*;
*(‘myBlinkData’, *(data));
//Now I can add some code do display item.
This thing grabs the current visibility state from storage, flips it (true becomes false, false becomes true), and then saves it back. I use a simple object.
Making It Happen Regularly
Of course, blinking only happens once isn’t really blinking. I needed to repeat the process. Here is how:
javascript
setInterval(blink, 500); // Blink every half a second
So it will excute the function “blink” every 0.5 second.
Putting It All Together
I then put all code together
javascript
*(‘myBlinkData’, *({ isVisible: true }));
function blink() {
let data = *(*(‘myBlinkData’));
* = !*;
*(‘myBlinkData’, *(data));
//Now I can add some code do display item.
setInterval(blink, 500); // Blink every half a second
It worked! I mean, it’s super basic, but it blinks. And it’s all done with local storage, no fancy frameworks or libraries. It can be used for any purpose.