Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript
523 B
Raw Blame
export default function stateFactory (changeCallback = () => {}) {
  const stateChangeHandler = {
    get (target, key) {
      if (typeof target[key] === 'object' && target[key] !== null) {
        return new Proxy(target[key], stateChangeHandler)
      }
      return target[key]
    },
    set (target, prop, value) {
      target[prop] = value
      if (target[prop] !== value) changeCallback(target)
      return true
    }
  }

  return new Proxy({
    downloading: {},
    summarizing: {}
  }, stateChangeHandler)
}