Skip to content

.mixProcess

Peter Naydenov edited this page Dec 17, 2017 · 1 revision

Set new process as combination of existing processes.

tplEngine.mixProcess ( mixList, newProcessName )

  • mixList: string[]. Process names that will be included;
  • newProcessName: string;
  • Method return options:
    • tplEngine;
  • Method is chainable;

Example:

 const templates = {
                         'li'   : '<li>{{text}}</li>'
                       , 'ul'   : '<ul>{{text}}</ul>'
                    }
   const doListItems = [
                         { do:'set', as: 'text' }
                       , { do: 'draw', tpl: 'li' }                       
                     ]
   const doUList = [
                       { do: 'block' }
                     , { do: 'set', as: 'text' }
                     , { do: 'draw', tpl: 'ul' }
                     , { do: 'block', name: 'friends' }  // save block 'friends'
                    ]
                    
 tplEngine
   .insertTemplate ( templates )
   .insertProcess ( doListItems, 'doItems')     // define process 'doItems'
   .insertProcess ( doUList, 'doList' )         // define process 'doList'
   .mixProcess ( ['doItems', 'doList'], 'doUL')  // create new process 'doUL' as combination of 'doItems' and 'doUL'
   


 tplEngine.run ( 'doUL', ['Peter', 'Ivan', 'Ivo'])
 
 const result = tplEngine.getBlock ( 'friends' )
 // -> '<ul><li>Peter</li><li>Ivan</li><li>Ivo</li></ul>'

 

Runkit: playground available