Skip to content

Commit

Permalink
3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
imaustink committed Nov 1, 2017
1 parent c73de42 commit eba92b5
Show file tree
Hide file tree
Showing 3 changed files with 481 additions and 0 deletions.
119 changes: 119 additions & 0 deletions dist/amd/can-stache-converters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*can-stache-converters@3.2.2#can-stache-converters*/
define([
'require',
'exports',
'module',
'can-stache',
'can-util/js/string-to-any',
'can-util/js/make-array',
'can-util/js/dev',
'can-stache-bindings'
], function (require, exports, module) {
var stache = require('can-stache');
var stringToAny = require('can-util/js/string-to-any');
var makeArray = require('can-util/js/make-array');
var dev = require('can-util/js/dev');
require('can-stache-bindings');
stache.registerConverter('boolean-to-inList', {
get: function (item, list) {
if (!list) {
return false;
} else {
return list.indexOf(item) !== -1;
}
},
set: function (newVal, item, list) {
if (!list) {
return;
}
if (!newVal) {
var idx = list.indexOf(item);
if (idx !== -1) {
list.splice(idx, 1);
}
} else {
list.push(item);
}
}
});
stache.registerConverter('string-to-any', {
get: function (compute) {
return '' + compute();
},
set: function (newVal, compute) {
var converted = stringToAny(newVal);
compute(converted);
}
});
stache.registerConverter('not', {
get: function (compute) {
return !compute();
},
set: function (newVal, compute) {
compute(!newVal);
}
});
stache.registerConverter('index-to-selected', {
get: function (item, list) {
var val = item.isComputed ? item() : item;
var idx = list.indexOf(val);
return idx;
},
set: function (idx, item, list) {
var newVal = list[idx];
if (item.isComputed) {
item(newVal);
}
}
});
stache.registerConverter('selected-to-index', {
get: function (idx, list) {
var val = idx.isComputed ? idx() : idx;
var item = list[val];
return item;
},
set: function (item, idx, list) {
var newVal = list.indexOf(item);
if (idx.isComputed) {
idx(newVal);
}
}
});
stache.registerConverter('either-or', {
get: function (chosen, a, b) {
var matchA = a === chosen();
var matchB = b === chosen();
if (!matchA && !matchB) {
return;
} else {
return matchA;
}
},
set: function (newVal, chosen, a, b) {
chosen(newVal ? a : b);
}
});
stache.registerConverter('equal', {
get: function () {
var args = makeArray(arguments);
if (args.length > 1) {
var comparer = args.pop();
return args.every(function (compute) {
return (compute && compute.isComputed ? compute() : compute) === comparer;
});
}
},
set: function () {
var args = makeArray(arguments);
if (args.length > 2) {
var b = args.shift();
var comparer = args.pop();
if (b) {
for (var i = 0; i < args.length; i++) {
args[i](comparer);
}
}
}
}
});
});
108 changes: 108 additions & 0 deletions dist/cjs/can-stache-converters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*can-stache-converters@3.2.2#can-stache-converters*/
var stache = require('can-stache');
var stringToAny = require('can-util/js/string-to-any/string-to-any');
var makeArray = require('can-util/js/make-array/make-array');
var dev = require('can-util/js/dev/dev');
require('can-stache-bindings');
stache.registerConverter('boolean-to-inList', {
get: function (item, list) {
if (!list) {
return false;
} else {
return list.indexOf(item) !== -1;
}
},
set: function (newVal, item, list) {
if (!list) {
return;
}
if (!newVal) {
var idx = list.indexOf(item);
if (idx !== -1) {
list.splice(idx, 1);
}
} else {
list.push(item);
}
}
});
stache.registerConverter('string-to-any', {
get: function (compute) {
return '' + compute();
},
set: function (newVal, compute) {
var converted = stringToAny(newVal);
compute(converted);
}
});
stache.registerConverter('not', {
get: function (compute) {
return !compute();
},
set: function (newVal, compute) {
compute(!newVal);
}
});
stache.registerConverter('index-to-selected', {
get: function (item, list) {
var val = item.isComputed ? item() : item;
var idx = list.indexOf(val);
return idx;
},
set: function (idx, item, list) {
var newVal = list[idx];
if (item.isComputed) {
item(newVal);
}
}
});
stache.registerConverter('selected-to-index', {
get: function (idx, list) {
var val = idx.isComputed ? idx() : idx;
var item = list[val];
return item;
},
set: function (item, idx, list) {
var newVal = list.indexOf(item);
if (idx.isComputed) {
idx(newVal);
}
}
});
stache.registerConverter('either-or', {
get: function (chosen, a, b) {
var matchA = a === chosen();
var matchB = b === chosen();
if (!matchA && !matchB) {
return;
} else {
return matchA;
}
},
set: function (newVal, chosen, a, b) {
chosen(newVal ? a : b);
}
});
stache.registerConverter('equal', {
get: function () {
var args = makeArray(arguments);
if (args.length > 1) {
var comparer = args.pop();
return args.every(function (compute) {
return (compute && compute.isComputed ? compute() : compute) === comparer;
});
}
},
set: function () {
var args = makeArray(arguments);
if (args.length > 2) {
var b = args.shift();
var comparer = args.pop();
if (b) {
for (var i = 0; i < args.length; i++) {
args[i](comparer);
}
}
}
}
});
Loading

0 comments on commit eba92b5

Please sign in to comment.