Socket
Socket
Sign inDemoInstall

ampersand-dom-bindings

Package Overview
Dependencies
Maintainers
3
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ampersand-dom-bindings - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

12

ampersand-dom-bindings.js

@@ -50,2 +50,3 @@ var Store = require('key-tree-store');

var type = binding.type || 'text';
var isCustomBinding = typeof type === 'function';
var selector = (function () {

@@ -62,7 +63,14 @@ if (typeof binding.selector === 'string') {

// storage variable for previous if relevant
var previousValue = '';
var previousValue;
if (type === 'text') {
if (isCustomBinding) {
return function (el, value) {
getMatches(el, selector).forEach(function (match) {
type(match, value, previousValue);
});
previousValue = value;
};
} else if (type === 'text') {
return function (el, value) {
getMatches(el, selector).forEach(function (match) {
dom.text(match, value);

@@ -69,0 +77,0 @@ });

2

package.json
{
"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.2.0",
"version": "3.3.0",
"author": "'Henrik Joreteg' <henrik@andyet.net>",

@@ -6,0 +6,0 @@ "bugs": {

@@ -443,2 +443,58 @@ var test = require('tape');

// Custom bindings
test('custom binding', function (t) {
var el = getEl('<span class="thing"></span>');
var custom = function (bindingEl, value, previous) {
var msg = value + ' is the new value.';
msg += typeof previous !== 'undefined' ? ' previous value was ' + previous + '.' : '';
dom.text(bindingEl, msg);
};
var bindings = domBindings({
'model': {
type: custom,
selector: '.thing'
}
});
t.equal(el.firstChild.textContent, '');
bindings.run('model', null, el, 'hello');
t.equal(el.firstChild.textContent, 'hello is the new value.');
bindings.run('model', null, el, 'goodbye');
t.equal(el.firstChild.textContent, 'goodbye is the new value. previous value was hello.');
bindings.run('model', null, el, '');
t.equal(el.firstChild.textContent, ' is the new value. previous value was goodbye.');
bindings.run('model', null, el, 'goodbye');
t.equal(el.firstChild.textContent, 'goodbye is the new value. previous value was .');
t.end();
});
//Bad type is an error
test('Errors on a bad type', function (t) {
function bindings(type) {
return function () {
domBindings({
'model': {
type: type,
selector: '.thing'
}
});
};
}
function errMsg(msg) {
return new RegExp(('no such binding type: ' + msg).replace(/[\[\]]/g, '\\$&'));
}
t.throws(bindings('not-a-type'), errMsg('not-a-type'));
t.throws(bindings({}), errMsg({}));
t.throws(bindings([]), errMsg([]));
t.end();
});
// TODO: tests for toggle

@@ -445,0 +501,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc