All files templit.js

100% Statements 20/20
83.33% Branches 5/6
100% Functions 5/5
100% Lines 20/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29    1x     1x   1x   1x     22x 22x 88x     22x 110x   22x   22x   22x 21x   1x 1x
import { Template } from './Template.js';
 
const templateCache = new Map();
 
function html(location) {
  return function(strings, ...values) {
    const output = strings.map((string, index) =>
      `${string ? string : ''}${values[index] ? '---!{' + values[index] + '}!---' : ''}`).join('');
    const templateKey = btoa(strings.join(''));
 
    let compiler = templateCache.get(templateKey);
 
    if (compiler) {
      compiler.update(output);
    } else {
      compiler = new Template(output, location, this);
      templateCache.set(templateKey, compiler);
    }
  }
}
 
export function templit(location, context) {
  function render(...args) {
    const renderer = Reflect.apply(html, context, [location]);
    return Reflect.apply(renderer, context, args);
  }
  return render.bind(context);
}