Procházet zdrojové kódy

ProgressDrawer work in progress, trying out virtual-dom & main-loop

Artur Paikin před 9 roky
rodič
revize
e71d87a677
1 změnil soubory, kde provedl 62 přidání a 0 odebrání
  1. 62 0
      src/plugins/ProgressDrawer.js

+ 62 - 0
src/plugins/ProgressDrawer.js

@@ -0,0 +1,62 @@
+import Plugin from './Plugin'
+import vdom from 'virtual-dom'
+import hyperx from 'hyperx'
+import main from 'main-loop'
+
+// should be core methods/members
+const hx = hyperx(vdom.h)
+const loop = main({clickedTimes: 0}, this.render, vdom)
+// require('./actions.js')(bus, loop)
+
+/**
+ * Progress drawer
+ *
+ */
+export default class ProgressDrawer extends Plugin {
+  constructor (core, opts) {
+    super(core, opts)
+    this.type = 'progressindicator'
+
+    // set default options
+    const defaultOptions = {}
+
+    // merge default options with the ones set by user
+    this.opts = Object.assign({}, defaultOptions, opts)
+  }
+
+  render (state) {
+    return hx`<div>
+      ${state.bla}
+    </div>`
+  }
+
+  // all actions should be in core, I guess
+  events () {
+    this.core.emitter.on('progress', function () {
+      this.updateState({ progress: loop.state.clickedTimes + 1 })
+    })
+
+    this.core.emitter.on('linkClicked', function () {
+      this.updateState({ linkClicked: 'даааа!' })
+    })
+  }
+
+  // this too should be a common method
+  updateState (updatedState) {
+    loop.update(Object.assign({}, loop.state, updatedState))
+  }
+
+  init () {
+    // const caller = this
+    // this.target = this.getTarget(this.opts.target, caller)
+    // this.targetEl = document.querySelector(this.target)
+    // this.targetEl.innerHTML = this.render()
+    document.querySelector('.UppyModal').appendChild(loop.target)
+  }
+
+  install () {
+    this.init()
+    this.events()
+    return
+  }
+}