Skip to content

ynoplanetashka2/completion-array

Repository files navigation

completion-array

Creates list of switches and invoke callback after all switches get switched

api

createCompletionArray :

import { createCompletionArray } from 'completion-array';

const [complete0, complete1] = createCompletionArray(2, () => console.log('all items completed'));

complete0()
complete0()
// nothing happend

complete1()
// logs: 'all items completed'

complete1()
complete0()
// nothing happend

createCompletionFn :

import { createCompletionFn } from 'completion-array';

const complete = createCompletionFn(2, () => console.log('all items completed'));

complete(0)
complete(0)
// nothing happend

complete(1)
// logs: 'all items completed'

complete(1)
complete(0)
// nothing happend

Also you can check src/__tests__ in git repo for more examples.

use case

Say your code needs to save completion state of a list of elements, and after all the elements are completed, perform some action. It's exactly the reason behind creation of this package.

Author

email: mrynoplanetashka@gmail.com

License

MIT (See LICENSE for more info)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published