GitXplorerGitXplorer
t

setter

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
1c47a9bcc86b6ec568405785650e887c1222e268

Release 0.0.2

ttimoxley committed 12 years ago
Unverified
fbd1dd82b50d1c587119bde0d0cb8b717149558a

Rename to setter to avoid confusion with set datastructure.

ttimoxley committed 12 years ago
Unverified
0410f329f64c844711ee19bed704e372bb8aa221

Tidy readme.

ttimoxley committed 12 years ago
Unverified
57957659ef1cb4f841a42180fa906eee3c2d9840

Add Example to Readme

ttimoxley committed 12 years ago
Unverified
077532804c86dbb41efcf669da1c62dc8cc57863

Initial commit

ttimoxley committed 12 years ago

README

The README file for this repository.

setter

Generate setter functions from string paths.

Installation

$ component install timoxley/setter

Examples

Simple Properties

var setter = require('setter')

var widget = {
  enabled: false
}

var setEnabled = setter(widget, 'enabled')
console.log(widget.enabled) // => false
setEnabled(true)
console.log(widget.enabled) // => true

Nested Properties

var user = {
  name: {
    first: 'Tim',
    last: 'Oxley'
  }
}

var setFirstName = setter(user, 'name.first')
setFirstName('Timothy')
console.log(user.name.first) // =>  'Timothy')

Intermediate properties are created if they do not exist

var user = {}

var setFirstName = setter(user, 'name.first')
setFirstName('Timothy')
console.log(user.name.first) // => 'Timothy'

Context is optional until setter() time

var user = {}

var setFirstName = setter('name.first')
setFirstName(user, 'Timothy')
console.log(user.name.first) // => 'Timothy'

context is set to this if not supplied

var user = {}

user.setFirstName = setter('name.first')
user.setFirstName('Timothy')
console.log(user.name.first) // => 'Timothy'

License

MIT