1.0.0 • Published 9 years ago
prop-bind v1.0.0
prop-bind
Create a property that changes value base another property
example
Create an element and bind the prop:
var propBind = require('prop-bind')
function MyButton (el) {
propBind(this, 'className', ':my-button checked:is-checked:not-checked')
this.checked = false
}
Then when the element is used:
var button = new MyButton()
console.log(button.className) // = 'my-button not-checked'
button.checked = true
console.log(button.className) // = 'my-button is-checked'
api
propBind(object, property, binding)
object
- The object that contains the properties.property
- The name of the property to create.binding
- The string to create the bindings.
The binding
is space separated and the syntax can be:
':raw-string'
- Values starting with:
are treated as raw strings.'property'
- Will switch between'property'
and''
.'property:on:off'
- Will switch between'on'
and'off'
whetherproperty
istrue
orfalse
.'property::off'
- Will switch between''
and'off'
whetherproperty
istrue
orfalse
.
license
(c) 2015 Kyle Robinson Young. MIT License
1.0.0
9 years ago