The last word on uploading files.
"Uppy is a sleek, modular file uploader that integrates seemlessly with any framework. It's fast, easy to use and let's you worry about more important problems than building a file uploader.
- capabilities is mentioned before explained
- capabilities could also be confused with the crypto equivalent - different meaning tho it's cool probably
- capabilities also seem enumerable - enumerating them is probably worth it
- addFile() mentions plugin types - shoulda been mentioned sooner
- consider using hemingway
- or run this:
#!/bin/zsh
where alex >/dev/null
[ $? -eq 0 ] || npm i -g alex
where write-good >/dev/null
[ $? -eq 0 ] || npm i -g write-good
where aspell >/dev/null
[ $? -eq 0 ] || brew install aspell
printf '[aspell] running\n'
aspell check "$1"
printf '[write-good] running\n'
write-good "$1"
printf '[alex] running\n'
alex "$1"
- file size cuts rely on dead code elimination rather than specific imports
- terminology isn't always clear
- mash up of different API types (event emitter, external state, prototypes)
- not sure how to create new plugins
- import with
/
is not great for file sizes; not necessarily an issue with rollup but that's not for everyone new
can be unwieldy - useif (!(this insteanceof Foo))
Core
is an odd name; the thing being used is theuppy
file transfer framework; all instances ofCore
in code will look odd in the light of a real application I reckon- The
core
setup discourages third party integrations; they'd be imported differenty which leaves others to feel a bit lackluster - feels use of prototypes is leaking into API design - it's an implementation detail, really
- found it unintuitive they plugins were called by uppy rather than initialized by the user
- found it unintuitive args are passed later
- feels technical implementation is leaking into plugin design
- using closures is fine and given it's not in the hot path it's fast enough
- if there's only a single mandatory argument, it makes sense to make it the
first arg passed
- breaks the current single opts arg passing paradigm
- makes for a more intuitive API
- again: not hot path so it's all cool
state [patch] -> uppy -> state [complete]
const Progress = require('uppy/progress')
const dnd = require('uppy/drag-and-drop')
const tus10 = require('uppy/tus10')
const uppy = require('uppy')
const upload = uppy()
upload.use(dnd('#drop-target'))
upload.use(function (state, cb) {
const newState = changeState
cb(null, newState)
})
upload.use(Progress({ appendChild: 'body' }))
app.model({
namespace: 'uppy',
reducers: {
update: function(state, data) {
return data
},
addFile: function (state, data) {
return state.files.push(data)
}
}
state: {}
})
function (state, prev, send) {
const opts = { thumbnails: false }
const el = upload(opts, (err, state) => {
if (err) throw err
send('update', state)
})
document.body.appendChild(el)
}
el.set({ my: 'state' })
- so
.use()
would detect the.plugin
value on any given value passed in and use that as a plugin - allows for using a result as both a plugin and DOM render target without needing to introduce more keywords. - Just pass it in; similar to how pull-stream does it - lil bit of polymorphism is cool
We're not Java - heavy taxonomy is not cool. Uppy should be allowed to modify state in whichever way it wants. When all updates are done, callback is called with new state which can be used by any other framework if desired.
Default state:
{ files: [] }
Internal:
{ files: [ { file: File, thumbnail: Image }] }
// or
{ files: [], thumbnails: { filename: Image } }
- getState - remove and make part of callback
- setState - rename to set(), partial setting of vars is cool
- updateAll() - if state is flushed on each set, this is not needed
- updateMeta() - make files part of state
- addFile() - just push to files array OR perhaps we do need a special file adding API - it could make sense; matter of taste and what a file looks like internally
- capabilities - not needed; just read out state
- log - not needed; hooks that tie into lifecycle events might be more interesting - any more debuggint than that feels off
- .on(), .emit(), .emitter - not needed; use state
uppy.set({ files: [ File ] })
- Drag and Drop & Progressbar are inconsistent
- drag and drop adds functionality to a selector
- progress injects an element into the selector
First of all, thanks for you suggestions on everything! We are going to be gradually implementing most of them. These are questions I still have, I understand some of them might be answered in your proposal, this means I didn’t understand that part, sorry for that.
1. Do you think we should separate logic components/plugins from views? Now they are coupled together — when you update state (logic), re-render is called on all plugins. If we do that, we can in theory re-use logic in all environments that support JS, while suppling separate React/React Native/JSX/Bel/Angular/Whatever UI component.
So, for example, for Google Drive plugin this would mean you can do something like this:
So
gdrive
only provides logicgdrive.getFiles()
,gdrive.getFileInfo(fileID)
. Maybe this is close to your proposal? But then how do we re-rendermyView
automatically? And all setup becomes complicated for the user, like “combine this logic with this view that accepts the right props”.2.
This works when I need to add a file, or show a message, for example, in some plugin:
What about when a user clicks “upload” button in some view, say Dashboard plugin, and I need to start the upload, which is handled by Uploader plugin? That’s what we had events for — similar to reducers in Choo:
click --> uppy.emit('core:start-upload')
, which is same assend('start-upload')
in Choo. Example: uploader plugin reacts toremove-file
event, which happens when file is removed from state, and cancels the upload. How would this work if plugins can only modify state, should they set a flag likenewState = {beginUpload: true}
?In short, plugin to plugin communication. You do have model and send in your proposal, but I don’t get what is that function that returns
el
— uppy itself? But we might want to mount to multiple places, like we do know, and like you show withupload.use(Progress({ appendChild: 'body' }))
.Don’t get that part. In your proposed example plugins look like this:
function (state, cb) {}
. Where would the.plugin
go? Or do you mean we keep current structure where plugins are objects that have methods and properties?3. Props vs
send/dispatch
— components can be re-used easier when they only get props, right?If I understand correctly, the philosophy is sort of: Choo is for apps/smart widgets, so we have
(state, prev, send)
, when Bel is for simple elements, so just pass whatever they need:(onSelect, onRemove, onDone, currentProgress)
.4. State can sometimes get updated like 10 times per second, and I only need to show progress every second. Where do I debounce this: in uploader plugin that updates state with progress, or in view that displays progress?
5. In Choo you use Request Animation Frame. Should we do that too? What if we just wrap yo.update() in a window.requestAnimationFrame()? Not sure I understand why raf and nanoraf modules exist (I did look inside, but still confused), node support?
6. We might feel like yo-yo is not working for us, because:
img src=
”In that case, what do you think we could switch to?
So far I’ve found Preact’s virtual dom and rendering works like I expect, but I did not use any of the component magic there, just virtual dom and rendering, here it is, preact+JSX and preact+hyperx: http://www.webpackbin.com/NJymHWsJf. The virtual-dom module is not good with SVG — didn’t play nice with our views last I tried. Any other good virtual-dom modules I overlooked?
In short: the current standard, React, is good for apps, but too big and complex for a lib. And yo-yo is small and cool, and I like it, but not battle-tested enough, so we are running into issues that have been solved in React and various virtual-dom.