src/basis/template.js
function buildTemplate(){
    // build new declaration
    var declaration = getDeclFromSource(this.source, this.baseURI, false, {
      isolate: this.getIsolatePrefix()
    });

    // make functions and assign to template
    var destroyBuilder = this.destroyBuilder;
    var instances = {};
    var funcs = this.builder(declaration.tokens, instances);
    this.createInstance = funcs.createInstance;
    this.clearInstance = funcs.destroyInstance;
    this.destroyBuilder = funcs.destroy;

    store.add(this.templateId, this, instances);

    // for debug purposes only
    /** @cut */ this.instances_ = instances;
    /** @cut */ this.decl_ = declaration;


    // process dependencies
    var newDeps = declaration.deps;
    var oldDeps = this.deps_;
    this.deps_ = newDeps;

    // detach old deps
    if (oldDeps)
      for (var i = 0, dep; dep = oldDeps[i]; i++)
        dep.bindingBridge.detach(dep, templateSourceUpdate, this);

    // attach new deps
    if (newDeps)
      for (var i = 0, dep; dep = newDeps[i]; i++)
        dep.bindingBridge.attach(dep, templateSourceUpdate, this);


    // apply resources
    // start use new resource list and than stop use old resource list,
    // in this order FOUC is less possible
    var newResources = declaration.resources;
    var oldResources = this.resources;
    this.resources = newResources;

    if (newResources)
      for (var i = 0, item; item = newResources[i]; i++)
      {
        var resource = basis.resource(item.url).fetch();
        if (typeof resource.startUse == 'function')
          resource.startUse();
      }

    if (oldResources)
      for (var i = 0, item; item = oldResources[i]; i++)
      {
        var resource = basis.resource(item.url).fetch();
        if (typeof resource.stopUse == 'function')
          resource.stopUse();
      }


    // destroy old instances if any
    if (destroyBuilder)
      destroyBuilder(true);
  }
function buildTemplate(){
    // build new declaration
    var declaration = getDeclFromSource(this.source, this.baseURI, false, {
      isolate: this.getIsolatePrefix()
    });

    // make functions and assign to template
    var destroyBuilder = this.destroyBuilder;
    var instances = {};
    var funcs = this.builder(declaration.tokens, instances);
    this.createInstance = funcs.createInstance;
    this.clearInstance = funcs.destroyInstance;
    this.destroyBuilder = funcs.destroy;

    store.add(this.templateId, this, instances);

    // for debug purposes only
    /** @cut */ this.instances_ = instances;
    /** @cut */ this.decl_ = declaration;


    // process dependencies
    var newDeps = declaration.deps;
    var oldDeps = this.deps_;
    this.deps_ = newDeps;

    // detach old deps
    if (oldDeps)
      for (var i = 0, dep; dep = oldDeps[i]; i++)
        dep.bindingBridge.detach(dep, templateSourceUpdate, this);

    // attach new deps
    if (newDeps)
      for (var i = 0, dep; dep = newDeps[i]; i++)
        dep.bindingBridge.attach(dep, templateSourceUpdate, this);


    // apply resources
    // start use new resource list and than stop use old resource list,
    // in this order FOUC is less possible
    var newResources = declaration.resources;
    var oldResources = this.resources;
    this.resources = newResources;

    if (newResources)
      for (var i = 0, item; item = newResources[i]; i++)
      {
        var resource = basis.resource(item.url).fetch();
        if (typeof resource.startUse == 'function')
          resource.startUse();
      }

    if (oldResources)
      for (var i = 0, item; item = oldResources[i]; i++)
      {
        var resource = basis.resource(item.url).fetch();
        if (typeof resource.stopUse == 'function')
          resource.stopUse();
      }


    // destroy old instances if any
    if (destroyBuilder)
      destroyBuilder(true);
  }
function buildTemplate ( ) { // build new declaration var declaration = getDeclFromSource ( this . source , this . baseURI , false , { isolate : this . getIsolatePrefix ( ) } ) ; // make functions and assign to template var destroyBuilder = this . destroyBuilder ; var instances = { } ; var funcs = this . builder ( declaration . tokens , instances ) ; this . createInstance = funcs . createInstance ; this . clearInstance = funcs . destroyInstance ; this . destroyBuilder = funcs . destroy ; store . add ( this . templateId , this , instances ) ; // for debug purposes only /** @cut */ this . instances_ = instances ; /** @cut */ this . decl_ = declaration ; // process dependencies var newDeps = declaration . deps ; var oldDeps = this . deps_ ; this . deps_ = newDeps ; // detach old deps if ( oldDeps ) for ( var i = 0 , dep ; dep = oldDeps [ i ] ; i ++ ) dep . bindingBridge . detach ( dep , templateSourceUpdate , this ) ; // attach new deps if ( newDeps ) for ( var i = 0 , dep ; dep = newDeps [ i ] ; i ++ ) dep . bindingBridge . attach ( dep , templateSourceUpdate , this ) ; // apply resources // start use new resource list and than stop use old resource list, // in this order FOUC is less possible var newResources = declaration . resources ; var oldResources = this . resources ; this . resources = newResources ; if ( newResources ) for ( var i = 0 , item ; item = newResources [ i ] ; i ++ ) { var resource = basis . resource ( item . url ) . fetch ( ) ; if ( typeof resource . startUse == 'function' ) resource . startUse ( ) ; } if ( oldResources ) for ( var i = 0 , item ; item = oldResources [ i ] ; i ++ ) { var resource = basis . resource ( item . url ) . fetch ( ) ; if ( typeof resource . stopUse == 'function' ) resource . stopUse ( ) ; } // destroy old instances if any if ( destroyBuilder ) destroyBuilder ( true ) ; }
Internal function to build declaration by template source,
attach it to template and setup synchronization.
Internal function to build declaration by template source attach it to template and setup synchronization .