function-once
Wraps a function so that it's only ever executed once.
Last updated a year ago by fabiospampinato .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install function-once 
SYNC missed versions from official npm registry.

Function Once

Wraps a function so that it's only ever executed once.

Note: this is always set to undefined and only functions that don't accept any arguments are supported, as using those with a function that's only ever executed once is practically just a footgun. If you need different this or different arguments you should probably use memoization instead.

Install

npm install function-once

Usage

import once from 'function-once';

// Let's make sure a function is at most executed only once

const rand = once (() => Math.random ());

rand (); // => 0.3344627371267874
rand (); // => 0.3344627371267874

License

MIT © Fabio Spampinato

Current Tags

  • 3.0.1                                ...           latest (a year ago)

2 Versions

  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |