JSPM

resetable

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5383
  • Score
    100M100P100Q133289F
  • License MIT

A sweet to define temporary values and clear them off conditionally

Package Exports

  • resetable

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 (resetable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

= 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

}

=== 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.