JSPM

call-once

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 72
  • Score
    100M100P100Q68453F
  • License ISC

Call a function once and no more

Package Exports

  • call-once

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (call-once) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Call Once

Limit dangerous function calls.

Install

$ npm install call-once

Usage

// Simple usage
var callOnce = require( 'call-once' )
var wrapped = callOnce( function( n ){
  setupNuclearTestPlant()
  return true
})

wrapped() // => true
wrapped() // => undefined
// Blocking and unblocking wrapped functions
var callOnce = require( 'call-once' )
var setup = callOnce( function( n ){
  setupNuclearTestPlant()
  return true
})

powerPlant.on( 'constructed', function(){
  setup()
})

president.on( 'cancel_project', function(){
  setup.block() // will prevent the function from being called at all
})

president.on( 'changed_mind', function(){
  setup.unblock() // will allow the function to be called again
})

Note: in reality this is more useful for stuff like promise resolutions on a timeout