<commit_before>"use strict"

import { c0, di } from 'libs'
import { flux } from 'flux'

var { annotate, Inject, Injector, Provide, TransientScope } = di

annotate(Context, new Provide(flux.Context))
annotate(Context, new Inject(flux.Init$store, flux.Init$view, flux.NextTick))
export function Context (init$store, init$view, nextTick) {
  var iterator = Context()
  function * Context () {

    var ctx = Object.assign.apply(null, yield [
      {}, init$store, init$view,
    ])

    ctx.$store.state.style = init$view.style
    nextTick.async()
    return ctx
  }
  return iterator
}

var _tick = {
  count: 0,
  fps: 120,
  t0: new Date,
  cache: [],
  snapshot () { this.count++ },
}

export function $tick () { return _tick }

//
annotate(NextTick, new TransientScope)
annotate(NextTick, new Provide(flux.NextTick))
annotate(NextTick, new Inject($tick, flux.$dispatcher, flux.Actions, flux.RePaint))
export function NextTick ($tick, $dispatcher, actions, paint) {
  var nextTick = c0(function * () {
    $tick.snapshot()
    if ($tick.count > 200) return console.log('done', $tick)

    yield actions   // resolving actions
    yield paint     // painting

    // TODO: dynamically find fix and $tick.delay
    var fix = 2
    $tick.delay = (1000/$tick.fps - fix)|0

    // console.log($tick.delay, (new Date - $tick.t0)/$tick.count)

    if ($tick.fps === 0) return
    if ($tick.fps < 0) return $dispatcher.get(NextTick)()
    if ($tick.fps >= 1000/4) return $dispatcher.get(NextTick).async()

    return $dispatcher.get(NextTick).timeout()
  })

  nextTick.async = setImmediate.bind(null, nextTick)
  nextTick.timeout = setTimeout.bind(null, nextTick, $tick.delay)
  return nextTick
}

//
annotate(Actions, new TransientScope)
annotate(Actions, new Provide(flux.Actions))
export function Actions (...actions) {
  var iterator = Actions()
  function * Actions () {
    for (let action of actions) {
      // processing all actions in series
      yield action
    }
  }
  return iterator
}
<commit_msg>added sync method to NextTick<commit_after>"use strict"

import { c0, di } from 'libs'
import { flux } from 'flux'

var { annotate, Inject, Injector, Provide, TransientScope } = di

annotate(Context, new Provide(flux.Context))
annotate(Context, new Inject(flux.Init$store, flux.Init$view, flux.NextTick))
export function Context (init$store, init$view, nextTick) {
  var iterator = Context()
  function * Context () {

    var ctx = Object.assign.apply(null, yield [
      {}, init$store, init$view,
    ])

    ctx.$store.state.style = init$view.style
    nextTick.async()
    return ctx
  }
  return iterator
}

var _tick = {
  count: 0,
  fps: 120,
  t0: new Date,
  cache: [],
  snapshot () { this.count++ },
}

export function $tick () { return _tick }

//
annotate(NextTick, new TransientScope)
annotate(NextTick, new Provide(flux.NextTick))
annotate(NextTick, new Inject($tick, flux.$dispatcher, flux.Actions, flux.RePaint))
export function NextTick ($tick, $dispatcher, actions, paint) {
  var nextTick = c0(function * () {
    $tick.snapshot()
    if ($tick.count > 200) return console.log('done', $tick)

    yield actions   // resolving actions
    yield paint     // painting

    // TODO: dynamically find fix and $tick.delay
    var fix = 2
    $tick.delay = (1000/$tick.fps - fix)|0

    // console.log($tick.delay, (new Date - $tick.t0)/$tick.count)

    if ($tick.fps === 0) return
    if ($tick.fps < 0) return $dispatcher.get(NextTick).sync()
    if ($tick.fps >= 1000/4) return $dispatcher.get(NextTick).async()

    return $dispatcher.get(NextTick).timeout()
  })

  nextTick.sync = nextTick
  nextTick.async = setImmediate.bind(null, nextTick)
  nextTick.timeout = (t) => {
    t = t || $tick.delay
    return setTimeout(nextTick, t|0)
  }
  return nextTick
}

//
annotate(Actions, new TransientScope)
annotate(Actions, new Provide(flux.Actions))
export function Actions (...actions) {
  var iterator = Actions()
  function * Actions () {
    for (let action of actions) {
      // processing all actions in series
      yield action
    }
  }
  return iterator
}

{'fraction_non_alphanumeric': 0.14191499755740108, 'fraction_numerical': 0.011968734733756717, 'mean_word_length': 3.422246220302376, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '1317851', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1339, 'n_words': 356}