https://github.com/artskydj/state-holder
Basic getter and setter for arbitrary data
https://github.com/artskydj/state-holder
Last synced: 3 months ago
JSON representation
Basic getter and setter for arbitrary data
- Host: GitHub
- URL: https://github.com/artskydj/state-holder
- Owner: ArtskydJ
- Created: 2015-02-20T21:01:59.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-01-02T17:15:51.000Z (over 10 years ago)
- Last Synced: 2025-02-19T09:38:11.843Z (about 1 year ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
state-holder
============
> Basic getter and setter for arbitrary data
[](https://travis-ci.org/ArtskydJ/state-holder)
# source code
I think the best way to describe this module is to show you its source code:
```js
module.exports = function StateHolder(thing) {
return {
get: function get() { return thing },
set: function set(x) { return thing = x }
}
}
```
That's it! Short and sweet!
# why
Perhaps you're saying "This is the dumbest module I've ever seen!" Well, maybe it is, but it solved a problem for me. You can pass either `state.set` or `state.get` to another function, and it can only set data or get data, but not vise versa.
# example
And a quick example of how to use it:
```js
var StateHolder = require('state-holder')
var state = StateHolder( 'hello' )
state.get() // => 'hello'
state.set() // => undefined
state.get() // => undefined
state.set('world') // => 'world'
state.get() // => 'world'
```
# api
```js
var StateHolder = require('state-holder')
```
## `var state = StateHolder( [thing] )`
Can be called with or without `new`.
The state is set to the value of `thing`. If `thing` is omitted, the state is set to `undefined`.
## `var thing = state.get()`
Returns the state.
## `state.set( [thing] )`
The state is set to the value of `thing`. If `thing` is omitted, the state is set to `undefined`. Whatever the state ends up being set to is returned.
# install
```bash
npm install state-holder
```
# license
[VOL](http://veryopenlicense.com)