<commit_before>
import { h } from './h'
import { define } from './define'
import { updateData } from './update-data'

class Component {
  constructor() { }

  update(patch) {
    this.beforeUpdate && this.beforeUpdate()
    this.beforeRender && this.beforeRender()
    if (patch) {
      this.data = this.data || {}
      Object.keys(patch).forEach(path =>{
        updateData(this.data, path, patch[path])
      })
    }
    this._weappRef.setData(this.data)
    this.updated && this.updated()
  }

  install() { }

  installed() { }

  uninstall() { }

  fire(type, data) {
    this._weappRef.triggerEvent(type, data)
  }
}

const WeElement = Component



function getGlobal() {
  if (
    typeof global !== 'object' ||
    !global ||
    global.Math !== Math ||
    global.Array !== Array
  ) {
    return (
      self ||
      window ||
      global ||
      (function () {
        return this
      })()
    )
  }
  return global
}

const root = getGlobal()
const mapping = {}

const definePage = function (name, ctor, path) {
  mapping[path] = {
    name,
    ctor
  }
}
const defineApp = function (name, ctor) {
  const ins = new ctor()
  const config = {}
  config.globalData = ins.globalData
  config.onLaunch = function () {
    ins.install && ins.install.call(this)
  }
  App(config)
}

function render() {

}

root.Omi = {
  define,
  Component,
  WeElement,
  render,
  h,
  definePage,
  defineApp

}
root.omi = root.Omi
root.omix = root.Omi
root.Omix = root.Omi
root.create = {
  Page: function (options) {
    const ins = new options.ctor
    const config = {}
    Object.keys(ins).forEach(key => {
      config[key] = ins[key]
    })

    config.onLoad = function (options) {
      ins._weappRef = this
      config.$$refs.forEach(ref => {
        if (ref.type === 'component') {
          if (ref.fn) {
            ref.fn(this.selectComponent('#' + ref.id))
          } else {
            ins[ref.refName] = this.selectComponent('#' + ref.id)
          }
        }
      })
      ins.install(options)
      ins.beforeRender && ins.beforeRender()
    }

    config.onReady = function () {
      ins.installed()
    }

    config.onUnload = function () {
      ins.uninstall()
    }

    config.onShow = function () {
      ins.show && ins.show()
    }

    config.onHide = function () {
      ins.hide && ins.hide()
    }

    if(ins.onReachBottom){
      config.onReachBottom = ins.onReachBottom.bind(ins)
    }

    if(ins.onPullDownRefresh){
      config.onPullDownRefresh = ins.onPullDownRefresh.bind(ins)
    }

    if(ins.onPageScroll){<commit_msg>omip - support callback of this.update<commit_after>
import { h } from './h'
import { define } from './define'
import { updateData } from './update-data'

class Component {
  constructor() { }

  update(patch, callback) {
    this.beforeUpdate && this.beforeUpdate()
    this.beforeRender && this.beforeRender()

    if (arguments.length === 0) {
      this._weappRef.setData(this.data)
    } else if (arguments.length === 1) {
      if (typeof patch === 'function') {
        this._weappRef.setData(this.data, patch)
      } else {
        this.data = this.data || {}
        Object.keys(patch).forEach(path => {
          updateData(this.data, path, patch[path])
        })
        this._weappRef.setData(this.data)
      }
    } else {
      this.data = this.data || {}
      Object.keys(patch).forEach(path => {
        updateData(this.data, path, patch[path])
      })
      this._weappRef.setData(this.data, callback)
    }
    this.updated && this.updated()
  }

  install() { }

  installed() { }

  uninstall() { }

  fire(type, data) {
    this._weappRef.triggerEvent(type, data)
  }
}

const WeElement = Component



function getGlobal() {
  if (
    typeof global !== 'object' ||
    !global ||
    global.Math !== Math ||
    global.Array !== Array
  ) {
    return (
      self ||
      window ||
      global ||
      (function () {
        return this
      })()
    )
  }
  return global
}

const root = getGlobal()
const mapping = {}

const definePage = function (name, ctor, path) {
  mapping[path] = {
    name,
    ctor
  }
}
const defineApp = function (name, ctor) {
  const ins = new ctor()
  const config = {}
  config.globalData = ins.globalData
  config.onLaunch = function () {
    ins.install && ins.install.call(this)
  }
  App(config)
}

function render() {

}

root.Omi = {
  define,
  Component,
  WeElement,
  render,
  h,
  definePage,
  defineApp

}
root.omi = root.Omi
root.omix = root.Omi
root.Omix = root.Omi
root.create = {
  Page: function (options) {
    const ins = new options.ctor
    const config = {}
    Object.keys(ins).forEach(key => {
      config[key] = ins[key]
    })

    config.onLoad = function (options) {
      ins._weappRef = this
      config.$$refs.forEach(ref => {
        if (ref.type === 'component') {
          if (ref.fn) {
            ref.fn(this.selectComponent('#' + ref.id))
          } else {
            ins[ref.refName] = this.selectComponent('#' + ref.id)
          }
        }
      })
      ins.install(options)
      ins.beforeRender && ins.beforeRender()
    }

    config.onReady = function () {
      ins.installed()
    }

    config.onUnload = function () {
      ins.uninstall()
    }

    config.onShow = function () {
      ins.show && ins.show()
    }

    config.onHide = function () {
      ins.hide && ins.hide()
    }

    if (ins.onReachBottom) {
      config.onReachBottom = ins.onReachBottom.bind(ins)
    }

    if (ins.onPullDownRefresh) {
      config.onPullDownRefresh = ins.onPullDownRefresh.bind(ins)
    }

    if (ins.onPageScroll) {
{'fraction_non_alphanumeric': 0.1493043168034249, 'fraction_numerical': 0.00035676061362825543, 'mean_word_length': 2.211340206185567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '3302812', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1849, 'n_words': 357}