marko/widgets/repeated-id.js
Patrick Steele-Idem 2277d97c44 Code size reduction
2016-12-20 17:06:52 -07:00

29 lines
806 B
JavaScript

var REPEATED_ID_KEY = '$rep';
function RepeatedId() {
this.$__nextIdLookup = {};
}
RepeatedId.prototype = {
$__nextId: function(parentId, id) {
var indexLookupKey = parentId + '-' + id;
var currentIndex = this.$__nextIdLookup[indexLookupKey];
if (currentIndex == null) {
currentIndex = this.$__nextIdLookup[indexLookupKey] = 0;
} else {
currentIndex = ++this.$__nextIdLookup[indexLookupKey];
}
return indexLookupKey.slice(0, -2) + '[' + currentIndex + ']';
}
};
exports.$__nextId = function(out, parentId, id) {
var repeatedId = out.global[REPEATED_ID_KEY];
if (repeatedId == null) {
repeatedId = out.global[REPEATED_ID_KEY] = new RepeatedId();
}
return repeatedId.$__nextId(parentId, id);
};