<commit_before>import { fnapp, fnstate, h } from 'https://cdn.jsdelivr.net/npm/fntags@0.3.2/src/fntags.min.js'

let data = fnstate( [], d => d.id )

function random( max ) { return Math.round( Math.random() * 1000 ) % max }

const A = ['pretty', 'large', 'big', 'small', 'tall', 'short', 'long', 'handsome', 'plain', 'quaint', 'clean',
    'elegant', 'easy', 'angry', 'crazy', 'helpful', 'mushy', 'odd', 'unsightly', 'adorable', 'important', 'inexpensive',
    'cheap', 'expensive', 'fancy']
const C = ['red', 'yellow', 'blue', 'green', 'pink', 'brown', 'purple', 'brown', 'white', 'black', 'orange']
const N = ['table', 'chair', 'house', 'bbq', 'desk', 'car', 'pony', 'cookie', 'sandwich', 'burger', 'pizza', 'mouse',
    'keyboard']

let nextId = 1

function buildData( count ) {
    const newData = new Array( count )
    for( let i = 0; i < count; i++ ) {
        newData[ i ] = {
            id: nextId++,
            label: `${A[ random( A.length ) ]} ${C[ random( C.length ) ]} ${N[ random( N.length ) ]}`
        }
    }
    return newData
}

const Button = ( id, title, onclick ) =>
    h( 'div', { class: 'col-sm-6 smallpad' },
       h( 'button', { id, type: 'button', class: 'btn btn-primary btn-block', onclick: onclick }, title )
    )

const row = ( item ) => {
    const id = h( 'td', {
                      class: 'col-md-1'
                  },
                  item().id
    )
    let label = h( 'a', item().label )
    let removeBtn = h( 'span', {
        onclick: ( e ) => {
            e.preventDefault()
            e.stopPropagation()
            data( data().filter( d => d().id !== item().id ) )
        },
        class: 'glyphicon glyphicon-remove', 'aria-hidden': 'true'
    } )

    const tr = h( 'tr', {
                      id: item().id,
                      onclick: () => {
                          let currentSelection = data().find( d => d().selected )
                          if( currentSelection ) currentSelection.patch( { selected: false } )
                          item.patch( { selected: true } )
                      }
                  },
                  id,
                  h( 'td', { class: 'col-md-4' }, label ),
                  h( 'td', { class: 'col-md-1' },
                     h( 'a',
                        removeBtn
                     )
                  ),
                  h( 'td', { class: 'col-md-6' } )
    )

    //cache the current values to prevent reading the dom or making the same change over the top of itself
    let currentLabel = item().label
    let isSelected = item().isSelected

    item.subscribe( () => {
        if( isSelected && !item().selected ) {
            tr.className = ''
        } else if( !isSelected && item().selected ) {
            tr.className = 'danger'
        }
        isSelected = item().selected

        if( currentLabel != item().label ) {
            label.innerText = item().label
            currentLabel = item().label<commit_msg>set class for selected on first load to ensure data is loaded correctly<commit_after>import { fnapp, fnstate, h } from 'https://cdn.jsdelivr.net/npm/fntags@0.3.2/src/fntags.min.js'

let data = fnstate( [], d => d.id )

function random( max ) { return Math.round( Math.random() * 1000 ) % max }

const A = ['pretty', 'large', 'big', 'small', 'tall', 'short', 'long', 'handsome', 'plain', 'quaint', 'clean',
    'elegant', 'easy', 'angry', 'crazy', 'helpful', 'mushy', 'odd', 'unsightly', 'adorable', 'important', 'inexpensive',
    'cheap', 'expensive', 'fancy']
const C = ['red', 'yellow', 'blue', 'green', 'pink', 'brown', 'purple', 'brown', 'white', 'black', 'orange']
const N = ['table', 'chair', 'house', 'bbq', 'desk', 'car', 'pony', 'cookie', 'sandwich', 'burger', 'pizza', 'mouse',
    'keyboard']

let nextId = 1

function buildData( count ) {
    const newData = new Array( count )
    for( let i = 0; i < count; i++ ) {
        newData[ i ] = {
            id: nextId++,
            label: `${A[ random( A.length ) ]} ${C[ random( C.length ) ]} ${N[ random( N.length ) ]}`
        }
    }
    return newData
}

const Button = ( id, title, onclick ) =>
    h( 'div', { class: 'col-sm-6 smallpad' },
       h( 'button', { id, type: 'button', class: 'btn btn-primary btn-block', onclick: onclick }, title )
    )

const row = ( item ) => {
    const id = h( 'td', {
                      class: 'col-md-1'
                  },
                  item().id
    )
    let currentLabel = item().label
    let label = h( 'a', item().label )
    let removeBtn = h( 'span', {
        onclick: ( e ) => {
            e.preventDefault()
            e.stopPropagation()
            data( data().filter( d => d().id !== item().id ) )
        },
        class: 'glyphicon glyphicon-remove', 'aria-hidden': 'true'
    } )

    let isSelected = item().selected
    const tr = h( 'tr', {
                      id: item().id,
                      class: isSelected ? 'danger' : '',
                      onclick: () => {
                          let currentSelection = data().find( d => d().selected )
                          if( currentSelection ) currentSelection.patch( { selected: false } )
                          item.patch( { selected: true } )
                      }
                  },
                  id,
                  h( 'td', { class: 'col-md-4' }, label ),
                  h( 'td', { class: 'col-md-1' },
                     h( 'a',
                        removeBtn
                     )
                  ),
                  h( 'td', { class: 'col-md-6' } )
    )

    item.subscribe( () => {
        if( isSelected && !item().selected ) {
            tr.className = ''
        } else if( !isSelected && item().selected ) {
            tr.className = 'danger'
        }
        isSelected = item().selected

        if( currentLabel != item().label ) {
            label.innerText = item().label
            currentLabel = item().label
{'fraction_non_alphanumeric': 0.1808960270498732, 'fraction_numerical': 0.004733727810650888, 'mean_word_length': 1.7100320659642694, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4535723', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1801, 'n_words': 485}