Skip to content
Time function calls. Repeat a function every n milliseconds.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
build
.babelrc
.gitignore
LICENSE
README.md
index.js
package.json
rollup.config.js

README.md

periodic.js

Install

  • npm install --save periodic.js

Usage

import PeriodicJS from 'periodic.js';

const displaySelector = '.periodic';
const periodic = PeriodicJS({
    duration: 3000,
    displaySelector,
    callback: fetchData
});

function fetchData(done) {

    // tell user we are fetching data
    var element = document.querySelector(displaySelector);
    element.innerHTML = 'updating';

    setTimeout(done, 3000);
}

Also add an element with the displaySelector class you provided earlier:

<p class='periodic'></p>
Something went wrong with that request. Please try again.