0.0.5 • Published 5 years ago

gentardator v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Work in progress, use at your own discretion

Gentardator

Helps perform asynchronous tasks on regular interval using javascript generators and recursion.

Installation

npm i gentardator
import { Generate } from 'gentardator'

Generate({
  task: () => console.log('updated'), // @function @required runs every _interval_
  stop: () => stop, // @function @optional stop generator when evaluates to true
  interval: 1000 // @number @required time between _task_ execution (ms)
})

Example with React Hooks

import React, { useState, useEffect } from 'react'
import axios from 'axios'
import { Generate } from 'gentardator'

const ItemDisplay = () => {
    const [items, setItems] = useState([])

    const getItemUpdates = async () => {
        const { data } = await axios.get(API)
        setItems(data)
    }

    useEffect(() => {
        Generate({
            task: getItemUpdates,
            interval: 5000
        })
    }, [])

    return (
        <div>
            {items.map(item => <p>{item.name}</p>)}
        </div>
    )
}
0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago