resetable v1.0.3
= Resetable A sweet to define temporary values and clear them off conditionally
== Setup
source, bash
npm i --save resetable
== Usage
source, javascript
const Resetable = require('resetable')
const name = new Resetable('defaultValue')
== What is this? You all love creating chainable functions, which set global value and once to use that global, you clean it off. Okay wait! Let's check the below example.
=== Without Resetable
source, javascript
const carStore = {} let carModel = null let carType = null
carStore.model = (model) => { carModel = model return carStore }
carStore.type = (type) => { carType = type return carStore }
carStore.search = () => { const model = carModel const type = carType carModel = null carType = null
// perform search
}
carStore .model('1990') .type('stang')
.search()
=== With Resetable
source, javascript
const Resetable = require('resetable')
const carStore = {} let carModel = new Resetable(null) <1> let carType = new Resetable(null)
carStore.model = (model) => { carModel.set(model) <2> return carStore }
carStore.type = (type) => { carType.set(type) return carStore }
carStore.search = () => { const model = carModel.pull() <3> const type = carType.pull()
// perform search
}
carStore .model('1990') .type('stang')
.search()
<1> Define the temporary variable as resetable with a default value.
<2> Make use of the set
method to set the value.
<3> Calling the pull
method will clear the resetable variable back to the original value.