xrfragment/src/3rd/js/index.js

35 lines
990 B
JavaScript
Raw Normal View History

2023-06-07 17:42:21 +02:00
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2023 Leon van Kammen/NLNET
var xrf = {}
xrf.init = function(opts){
opts = opts || {}
xrf.Parser.debug = xrf.debug
for ( let i in opts ) xrf[i] = opts[i]
xrf.emit('init',opts)
return xrf.query
}
xrf.query = function(){
// framework implementations can override this function, see src/3rd/js/three/index.sj
alert("queries are not implemented (yet) for this particular framework")
}
2023-06-09 16:40:08 +02:00
xrf.roundrobin = (frag, store) => {
if( !frag.args || frag.args.length == 0 ) return 0
if( !store.rr ) store.rr = {}
let label = frag.fragment
if( store.rr[label] ) return store.rr[label].next()
store.rr[label] = frag.args
store.rr[label].next = () => {
store.rr[label].index = (store.rr[label].index + 1) % store.rr[label].length
return store.rr[label].index
}
return store.rr[label].index = 0
}
2023-06-07 17:42:21 +02:00
// map library functions to xrf
for ( let i in xrfragment ) xrf[i] = xrfragment[i]