Giter Site home page Giter Site logo

state-holder's Introduction

state-holder

Basic getter and setter for arbitrary data

Build Status

source code

I think the best way to describe this module is to show you its source code:

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:

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

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

npm install state-holder

license

VOL

state-holder's People

Contributors

artskydj avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.