run-once

1.0.0 • Public • Published

run-once

Simply do something once, or once under a condition using custom namespaces.

function colorOfTheSky(color){
  var skyColor
  if(once('colorOfTheSky')){
   skyColor = 'The sky is' + color 
  }else{
   skyColor = 'The sky is falling'
  }
  console.log(skyColor)
}
colorOfTheSky('blue')
// Run once: The sky is blue
// Run again: The sky is falling
// Run and on: The sky is faling
// ...

function colorOfTheSky(color){
  var skyColor
  if(once('colorOfTheSky' + color)){
   skyColor = 'The sky is' + color 
  }else{
   skyColor = 'The sky is falling'
  }
  console.log(skyColor)
}
colorOfTheSky('blue')
// Run once: The sky is blue
// Run again: The sky is falling
// Run and on: The sky is faling
// ...
colorOfTheSky('red')
// Run once: The sky is red
// Run again: The sky is falling
// Run and on: The sky is faling
// ...

(c) 2016 Julien Etienne MIT

/run-once/

    Package Sidebar

    Install

    npm i run-once

    Weekly Downloads

    1

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • julien.etienne