<commit_before>// descriptive todos example - no shortcuts
var todos = {}

todos.controller = function(props) {

  this.todoItem = mag.prop([])
  this.onload = utils.onload

  this.add = function(text) {
    var item = {
      text: text,
      _completed: false,
      _onclick: function(index, e) {
        this.todoItem()[index]._completed = !this.todoItem()[index]._completed
        this.todoItem(this.todoItem()) // starts a redraw
      }.bind(this, this.todoItem().length),
      _config: function(node) {
        node.querySelector('input').checked = node.getAttribute('completed') == 'true' ? true : false
      }
    }
    this.todoItem().push(item)
  }.bind(this)

  this.remains = function() {
    return this.todoItem().filter(function(item) {
      return item._completed == false
    }).length
  }.bind(this)

  this.archive = function() {
    this.todoItem(this.todoItem().filter(function(item, index) {
      if (!item._completed) {
        return item
      }
    }))
  }.bind(this)
}

todos.view = function(element, props, state) {

  var todo = mag.prop(''),
    doAdd = function(e) {
      if (todo() == '') return
      state.add(todo())
      e.target.value = todo('')
    }

  state.remaining = state.remains()
  state.size = state.todoItem().length + ' remaining'

  state.total = {
    a: {
      _onclick: state.archive
    },
    _class: "total " + (state.todoItem().length > 0 ? 'show' : 'hide'),
  }

  if (state.remains() == 0 && state.todoItem().length > 0) {
    state.total._text = 'Done!'
    state.remaining = {
      _class: "remaining hide"
    }
    state.size = '';

  } else {
    state.remaining = {
      _class: "remaining",
      _text: state.remains() + ' of '
    }
    state.total._text = ''
  }

  state.input = {
    _onfocus: function() {
      this.value = ''
    },
    _value: todo(),
    _onchange: mag.withProp('value', todo),
    _onkeyup: function(e) {
      if (e.which == 13) {
        doAdd(e)
      }
    }
  }

  state.button = {
    _onclick: doAdd
  }
}

var utils = {}
utils.onload = function(element) {
  element.classList.remove("hide")
}

mag.logger(console) // comment to turn on/off
mag.module("todos", todos)

// simple nested/reuse module examples

var passFail = {}

passFail.view = function(element, props, state) {

  state.message = props.pass() ? props.message.pass : props.fail() ? props.message.fail : ""

  state._class = props.pass() ? 'success' : props.fail() ? 'error' : ''

  state.messaging = state.message
}

var build = {}
build.view = function(element, props, state) {
  var link = function() {
    var scripts = document.querySelectorAll('head script')
    var string = ''
    for (var k in scripts) {
      var url = scripts[k].src<commit_msg>Update script.js<commit_after>// descriptive todos example - no shortcuts
var todos = {}

todos.controller = function(props) {

  this.todoItem = mag.prop([])
  this.onload = utils.onload

  this.add = function(text) {
    var item = {
      text: text,
      _completed: false,
      _onclick: function(index, e) {
        this.todoItem()[index]._completed = !this.todoItem()[index]._completed
        this.todoItem(this.todoItem()) // starts a redraw
      }.bind(this, this.todoItem().length),
      _config: function(node) {
        node.querySelector('input').checked = node.getAttribute('completed') == 'true' ? true : false
      }
    }
    this.todoItem().push(item)
  }.bind(this)

  this.remains = function() {
    return this.todoItem().filter(function(item) {
      return item._completed == false
    }).length
  }.bind(this)

  this.archive = function() {
    this.todoItem(this.todoItem().filter(function(item, index) {
      if (!item._completed) {
        return item
      }
    }))
  }.bind(this)
}

todos.view = function(element, props, state) {

  var todo = mag.prop(''),
    doAdd = function(e) {
      if (todo() == '') return
      state.add(todo())
      e.target.value = todo('')
    }

  state.remaining = state.remains()
  state.size = state.todoItem().length + ' remaining'

  state.total = {
    a: {
      _onclick: state.archive
    },
    _class: "total " + (state.todoItem().length > 0 ? 'show' : 'hide'),
  }

  if (state.remains() == 0 && state.todoItem().length > 0) {
    state.total._text = 'Done!'
    state.remaining = {
      _class: "remaining hide"
    }
    state.size = '';

  } else {
    state.remaining = {
      _class: "remaining",
      _text: state.remains() + ' of '
    }
    state.total._text = ''
  }

  state.input = {
    _onfocus: function() {
      this.value = ''
    },
    _value: todo(),
    _onchange: mag.withProp('value', todo),
    _onkeyup: function(e) {
      if (e.which == 13) {
        doAdd(e)
      }
    }
  }

  state.button = {
    _onclick: doAdd
  }
}

var utils = {}
utils.onload = function(element) {
  element.classList.remove("hide")
}

mag.module("todos", todos)

// simple nested/reuse module examples

var passFail = {}

passFail.view = function(element, props, state) {

  state.message = props.pass() ? props.message.pass : props.fail() ? props.message.fail : ""

  state._class = props.pass() ? 'success' : props.fail() ? 'error' : ''

  state.messaging = state.message
}

var build = {}
build.view = function(element, props, state) {
  var link = function() {
    var scripts = document.querySelectorAll('head script')
    var string = ''
    for (var k in scripts) {
      var url = scripts[k].src
{'fraction_non_alphanumeric': 0.16565321540445918, 'fraction_numerical': 0.0018426386585590566, 'mean_word_length': 2.6114437791084497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '2933017', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1835, 'n_words': 365}