Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/julienetie/run-once

Simply do something once, or once under a condition
https://github.com/julienetie/run-once

Last synced: 16 days ago
JSON representation

Simply do something once, or once under a condition

Awesome Lists containing this project

README

        

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

```javascript
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
// ...
```
***
```javascript
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