ampersand-dom-bindings
Advanced tools
Comparing version 3.3.2 to 3.3.3
@@ -12,3 +12,3 @@ /*$AMPERSAND_VERSION*/ | ||
// like func(el, value, lastKeyName) | ||
module.exports = function (bindings) { | ||
module.exports = function (bindings, context) { | ||
var store = new Store(); | ||
@@ -26,6 +26,6 @@ var key, current; | ||
current.forEach(function (binding) { | ||
store.add(key, getBindingFunc(binding)); | ||
store.add(key, getBindingFunc(binding, context)); | ||
}); | ||
} else { | ||
store.add(key, getBindingFunc(current)); | ||
store.add(key, getBindingFunc(current, context)); | ||
} | ||
@@ -51,3 +51,3 @@ } | ||
function getBindingFunc(binding) { | ||
function getBindingFunc(binding, context) { | ||
var type = binding.type || 'text'; | ||
@@ -74,3 +74,3 @@ var isCustomBinding = typeof type === 'function'; | ||
getMatches(el, selector).forEach(function (match) { | ||
type(match, value, previousValue); | ||
type.call(context, match, value, previousValue); | ||
}); | ||
@@ -77,0 +77,0 @@ previousValue = value; |
{ | ||
"name": "ampersand-dom-bindings", | ||
"description": "Takes binding declarations and returns key-tree-store of functions that can be used to apply those bindings.", | ||
"version": "3.3.2", | ||
"version": "3.3.3", | ||
"author": "'Henrik Joreteg' <henrik@andyet.net>", | ||
@@ -6,0 +6,0 @@ "browserify": { |
@@ -162,3 +162,4 @@ # ampersand-dom-bindings | ||
`type` can also be a function. It will be run for each matching `el` with the | ||
`value` and `previousValue` of the property. | ||
`value` and `previousValue` of the property. The function is bound to the view | ||
declaring the bindings, so `this` refers to the view. | ||
@@ -165,0 +166,0 @@ ```js |
@@ -476,2 +476,20 @@ var test = require('tape'); | ||
test('custom binding with context', function (t) { | ||
var el = getEl('<span class="thing"></span>'); | ||
var custom = function (bindingEl) { | ||
dom.text(bindingEl, 'this.value was ' + this.value); | ||
}; | ||
var bindings = domBindings({ | ||
'model': { | ||
type: custom, | ||
selector: '.thing' | ||
} | ||
}, { value: 'goodbye' }); | ||
bindings.run('model', null, el, 'hello'); | ||
t.equal(el.firstChild.textContent, 'this.value was goodbye'); | ||
t.end(); | ||
}); | ||
//Bad type is an error | ||
@@ -478,0 +496,0 @@ test('Errors on a bad type', function (t) { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
40728
769
297
1