nl_tokens: Create a function that evaluates a tagged template to create a new subclass of { @link FogletProtocol } that implements the protocol described in the template . @param { string } protocolName - The name of the protocol @return { function } A function that evaluates a tagged template to create a new subclass of { @link FogletProtocol } @example const ExampleUnicastProtocol = defineProtocol ( example - unicast - protocol ) init $ { function ( base ) { this . _base = base ; }} get $ { function ( service ) { service . is . unicast () ; service . on . receive ( function ( id msg reply reject ) { if ( msg . number % this . _base === 0 ) reply ( $ { msg . number } is a multiple of $ { this . _base } ) ; else reject ( $ { msg . number } is not a multiple of $ { this . _base } ) ; } ) ; }} ;
pl_tokens: function define ( protocolName ) { return function ( services , ... callbacks ) { let builder const protocolClass = class extends FogletProtocol { constructor ( foglet , ... args ) { super ( protocolName , foglet , ... args ) } } // clean services names before building services . map ( str => str . trim ( ) ) . filter ( str => str . length > 0 ) . forEach ( ( name , index ) => { if ( name === 'init' || name === 'constructor' ) { builder = <mask> InitBuilder ( callbacks [ index ] ) } else { builder = new ServiceBuilder ( name ) callbacks [ index ] ( builder ) } builder . apply ( protocolClass ) } ) return protocolClass } }