rommelsantor / timeout Goto Github PK
View Code? Open in Web Editor NEWInteractive, stateful JS timeout enhancements
License: MIT License
Interactive, stateful JS timeout enhancements
License: MIT License
Hi @rommelsantor ,
I know this could be a controversial topic.
What do you think about switching this library to Typescript?
I am using your library in several larger inhouse projects. For that I have had to expand some functionality. I would love to do it by overriding. But that's not so safe if there is no possibility for type checking in place (in case the backend changes). Therefore I had to fork your project https://github.com/MarcusCalidus/Timeout.git
If you are into the idea of moving to Typescript I'd gladly offer my help for translating the library.
Hello,
I tried using this HTML to import the code:
<script crossorigin="anonymous" src="https://cdn.jsdelivr.net/npm/[email protected]/index.js">var exports = {};</script>But it gives me a ReferenceError as the title says above. From what I read, I believe I need to have CommonJS library imported.
I want to use this library for my repository that is hosted on GitHub Pages. Can you help me?
I know in the documentation it says that this "defeats the purpose of instantiate", however, the good thing about this lib is that key
feature which makes it easier to keep track of all timeouts from anywhere. I think this option will make it possible to the following:
let t = timeout.instantiate('huga', ()=>console.log('blah'), 3000);
// ... do things with t
// this should still work as usual, but we can't get this from anywhere else since there is no key
let toto = timeout.instantiate(()=>console.log('blah'), 3000);
somewhere else where there is no access to t
console.log('t remaining time: ', timeout.remaining('huga'));
// or get and use the instance here
let tt = timeout('huga');
tt.restart()
So I'm a little new at this, not sure what to expect, but it would be cool if there was a public method for invoking (and optionally clearing immediately?) the timeout. Obviously the function can be stored some where and later triggered manually & then the timeout cleared, but poking around in the code shows an invoke method of sorts already exists, it's just not public.
Something like this maybe? ๐คทโโ
const invoke = key => {
if (!pending(key)) { return; }
metadata[key].func(...metadata[key].params)
clear(key)
}
Would you accept a PR that publishes this to npm for easy installation? I could convert this to esnext modules, or I could add that as an option. The latter is more work. ๐
Why does smart-timeout have a production dependancy on @babel/preset-env?
Timeout.call(key)
This enables rekindling a dead timeout as if it's new
timeout.set('huga', ()=>console.log('huga done!'), 5000);
// ... later on after the whole thing is dead, maybe after 12000ms
timeout.renew('huga')
// if this was instantiated to t...
t.renew()
That will just reinstantiate the timeout and replace it in mem.
optionally we could set new delay
timeout.renew('huga', 400)
// if this was instantiated to t...
t.renew(400)
This package looks really good in terms of functionality. One area I see for improvement is the ability to reference a timeout itself as a variable and call all available functions on the timeout.
Having that ability will allow to create timers and pass them to different areas of my code that might want to know about it. Currently it is difficult to get status on a timeout if it was created in one file and then passed into another.
Here is an example of what I would like to see
const Timeout = require('smart-timeout');
let newTimeout = Timeout(function(){ return 'does stuff'}, 1000);
newTimeout.remaining();
newTimeout.executed();
etc...
Do you have additional thoughts on this?
Timeout called my callback only once !!
Timeout.set("cpu_info", getInformation, millisecs = 9000, ["cache", "voltage", "flags"]);
The remaining function is a God-sent, I think another one is missing, which I have been trying to use:
timeout.set('huga', ()=>console.log('huga done!'), 5000);
// ... later on just like remaining()...
timeout.elapsed('huga')
// => 3384
this is just the opposite of remaining
How do i pass a parameter(s) to Timeout.set()
e.g
in setTimeout(myfunction,10,param1,param2);
I have tried below but not working.
Timeout.set('key',myfunction,10,param1,param2)
as title
There is currently no way of getting information about the instance
timeout.set('huga', ()=>console.log('huga done!'), 5000);
// ... later we may want to know info about this timeout
timeout.info('huga')
// returns something like => { name: 'huga', cb ฦ, delay: 5000}
// if this was instantiated to t...
t.info()
Hi,
Is there something in the pipeline to restart the timeout. My idea: I start a timeout for creating a screen saver after 5 seconds, but if anything is touched, clicked or similar, the timeout should be restarted.
Thanks,
Roland
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.