src/fragments.js
function Fragments(options) {
  if (!options || !options.observations) {
    throw new TypeError('Must provide an observations instance to Fragments in options.');
  }

  this.compiling = false;
  this.observations = options.observations;
  this.globals = options.observations.globals;
  this.formatters = options.observations.formatters;
  this.animations = {};
  this.animateAttribute = 'animate';

  this.binders = {
    element: { _wildcards: [] },
    attribute: { _wildcards: [], _expr: /{{\s*(.*?)\s*}}(?!})/g, _delimitersOnlyInDefault: false },
    text: { _wildcards: [], _expr: /{{\s*(.*?)\s*}}(?!})/g }
  };

  // Text binder for text nodes with expressions in them
  this.registerText('__default__', registerTextDefault);

  function registerTextDefault(value) {
    this.element.textContent = (value != null) ? value : '';
  }

  // Text binder for text nodes with expressions in them to be converted to HTML
  this.registerText('{*}', function(value) {
    if (this.content) {
      this.content.remove();
      this.content = null;
    }

    if (typeof value === 'string' && value || value instanceof Node) {
      this.content = View.makeInstanceOf(toFragment(value));
      this.element.parentNode.insertBefore(this.content, this.element.nextSibling);
    }
  });

  // Catchall attribute binder for regular attributes with expressions in them
  this.registerAttribute('__default__', function(value) {
    if (value != null) {
      this.element.setAttribute(this.name, value);
    } else {
      this.element.removeAttribute(this.name);
    }
  });

  this.addOptions(options);
}
function Fragments(options) {
  if (!options || !options.observations) {
    throw new TypeError('Must provide an observations instance to Fragments in options.');
  }

  this.compiling = false;
  this.observations = options.observations;
  this.globals = options.observations.globals;
  this.formatters = options.observations.formatters;
  this.animations = {};
  this.animateAttribute = 'animate';

  this.binders = {
    element: { _wildcards: [] },
    attribute: { _wildcards: [], _expr: /{{\s*(.*?)\s*}}(?!})/g, _delimitersOnlyInDefault: false },
    text: { _wildcards: [], _expr: /{{\s*(.*?)\s*}}(?!})/g }
  };

  // Text binder for text nodes with expressions in them
  this.registerText('__default__', registerTextDefault);

  function registerTextDefault(value) {
    this.element.textContent = (value != null) ? value : '';
  }

  // Text binder for text nodes with expressions in them to be converted to HTML
  this.registerText('{*}', function(value) {
    if (this.content) {
      this.content.remove();
      this.content = null;
    }

    if (typeof value === 'string' && value || value instanceof Node) {
      this.content = View.makeInstanceOf(toFragment(value));
      this.element.parentNode.insertBefore(this.content, this.element.nextSibling);
    }
  });

  // Catchall attribute binder for regular attributes with expressions in them
  this.registerAttribute('__default__', function(value) {
    if (value != null) {
      this.element.setAttribute(this.name, value);
    } else {
      this.element.removeAttribute(this.name);
    }
  });

  this.addOptions(options);
}
function Fragments ( options ) { if ( ! options || ! options . observations ) { throw new TypeError ( 'Must provide an observations instance to Fragments in options.' ) ; } this . compiling = false ; this . observations = options . observations ; this . globals = options . observations . globals ; this . formatters = options . observations . formatters ; this . animations = { } ; this . animateAttribute = 'animate' ; this . binders = { element : { _wildcards : [ ] } , attribute : { _wildcards : [ ] , _expr : / {{\s*(.*?)\s*}}(?!}) / g , _delimitersOnlyInDefault : false } , text : { _wildcards : [ ] , _expr : / {{\s*(.*?)\s*}}(?!}) / g } } ; // Text binder for text nodes with expressions in them this . registerText ( '__default__' , registerTextDefault ) ; function registerTextDefault ( value ) { this . element . textContent = ( value != null ) ? value : '' ; } // Text binder for text nodes with expressions in them to be converted to HTML this . registerText ( '{*}' , function ( value ) { if ( this . content ) { this . content . remove ( ) ; this . content = null ; } if ( typeof value === 'string' && value || value instanceof Node ) { this . content = View . makeInstanceOf ( toFragment ( value ) ) ; this . element . parentNode . insertBefore ( this . content , this . element . nextSibling ) ; } } ) ; // Catchall attribute binder for regular attributes with expressions in them this . registerAttribute ( '__default__' , function ( value ) { if ( value != null ) { this . element . setAttribute ( this . name , value ) ; } else { this . element . removeAttribute ( this . name ) ; } } ) ; this . addOptions ( options ) ; }
A Fragments object serves as a registry for binders and formatters
@param {Observations} observations An instance of Observations for tracking changes to the data
A Fragments object serves as a registry for binders and formatters